Update to axum 0.4

This commit is contained in:
Edward Shen 2022-01-18 00:36:02 -08:00
parent 3393f40482
commit 08f3e940e4
Signed by: edward
GPG key ID: 19182661E818369F
3 changed files with 50 additions and 9 deletions

48
Cargo.lock generated
View file

@ -73,11 +73,12 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
[[package]] [[package]]
name = "axum" name = "axum"
version = "0.3.4" version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b4e96976b2022b23b2199168ff9b281e9ddc1aa795607d5cb7146868ca5c101" checksum = "310a147401c66e79fc78636e4db63ac68cd6acb9ece056de806ea173a15bce32"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"axum-core",
"bitflags", "bitflags",
"bytes", "bytes",
"futures-util", "futures-util",
@ -86,6 +87,7 @@ dependencies = [
"http-body", "http-body",
"hyper", "hyper",
"matchit", "matchit",
"memchr",
"mime", "mime",
"percent-encoding", "percent-encoding",
"pin-project-lite", "pin-project-lite",
@ -96,11 +98,25 @@ dependencies = [
"tokio", "tokio",
"tokio-util", "tokio-util",
"tower", "tower",
"tower-http", "tower-http 0.2.0",
"tower-layer", "tower-layer",
"tower-service", "tower-service",
] ]
[[package]]
name = "axum-core"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ca6c0b218388a7ed6a8d25e94f7dea5498daaa4fd8c711fb3ff166041b06fda"
dependencies = [
"async-trait",
"bytes",
"futures-util",
"http",
"http-body",
"mime",
]
[[package]] [[package]]
name = "base64" name = "base64"
version = "0.13.0" version = "0.13.0"
@ -653,6 +669,12 @@ dependencies = [
"pin-project-lite", "pin-project-lite",
] ]
[[package]]
name = "http-range-header"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bfe8eed0a9285ef776bb792479ea3834e8b94e13d615c2f66d03dd50a435a29"
[[package]] [[package]]
name = "httparse" name = "httparse"
version = "1.5.1" version = "1.5.1"
@ -1012,7 +1034,7 @@ dependencies = [
"signal-hook", "signal-hook",
"signal-hook-tokio", "signal-hook-tokio",
"tokio", "tokio",
"tower-http", "tower-http 0.1.2",
"tracing", "tracing",
"tracing-subscriber", "tracing-subscriber",
] ]
@ -1731,6 +1753,24 @@ dependencies = [
"tower-service", "tower-service",
] ]
[[package]]
name = "tower-http"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39ee603d6e665ecc7e0f8d479eedb4626bd4726f0ee6119cee5b3a6bf184cac0"
dependencies = [
"bitflags",
"bytes",
"futures-core",
"futures-util",
"http",
"http-body",
"http-range-header",
"pin-project-lite",
"tower-layer",
"tower-service",
]
[[package]] [[package]]
name = "tower-layer" name = "tower-layer"
version = "0.3.1" version = "0.3.1"

View file

@ -8,7 +8,7 @@ edition = "2021"
[dependencies] [dependencies]
omegaupload-common = { path = "../common" } omegaupload-common = { path = "../common" }
anyhow = "1" anyhow = "1"
axum = { version = "0.3", features = ["http2", "headers"] } axum = { version = "0.4", features = ["http2", "headers"] }
bincode = "1" bincode = "1"
# We don't care about which version (We want to match with axum), we just need # We don't care about which version (We want to match with axum), we just need
# to enable the feature # to enable the feature

View file

@ -22,12 +22,12 @@ use std::time::Duration;
use anyhow::Result; use anyhow::Result;
use axum::body::Bytes; use axum::body::Bytes;
use axum::error_handling::HandleErrorExt; use axum::error_handling::HandleError;
use axum::extract::{Extension, Path, TypedHeader}; use axum::extract::{Extension, Path, TypedHeader};
use axum::http::header::EXPIRES; use axum::http::header::EXPIRES;
use axum::http::StatusCode; use axum::http::StatusCode;
use axum::response::Html; use axum::response::Html;
use axum::routing::{get, post, service_method_routing}; use axum::routing::{get, get_service, post};
use axum::{AddExtensionLayer, Router}; use axum::{AddExtensionLayer, Router};
use chrono::Utc; use chrono::Utc;
use futures::stream::StreamExt; use futures::stream::StreamExt;
@ -83,8 +83,9 @@ async fn main() -> Result<()> {
let signals_handle = signals.handle(); let signals_handle = signals.handle();
let signals_task = tokio::spawn(handle_signals(signals, Arc::clone(&db))); let signals_task = tokio::spawn(handle_signals(signals, Arc::clone(&db)));
let root_service = service_method_routing::get(ServeDir::new("static")) let root_service = HandleError::new(get_service(ServeDir::new("static")), |_| async {
.handle_error(|_| Ok::<_, Infallible>(StatusCode::NOT_FOUND)); Ok::<_, Infallible>(StatusCode::NOT_FOUND)
});
axum::Server::bind(&"0.0.0.0:8080".parse()?) axum::Server::bind(&"0.0.0.0:8080".parse()?)
.serve({ .serve({