Update axum

This commit is contained in:
Joscha 2024-05-11 16:17:07 +02:00
parent 766a36426b
commit 42d551eb6e
5 changed files with 142 additions and 52 deletions

160
Cargo.lock generated
View file

@ -125,13 +125,13 @@ dependencies = [
[[package]] [[package]]
name = "askama_axum" name = "askama_axum"
version = "0.3.0" version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07b336dea26a2eb67f04e1134385721f794b654a870ce5146d2fcb69ea39c3a4" checksum = "a41603f7cdbf5ac4af60760f17253eb6adf6ec5b6f14a7ed830cf687d375f163"
dependencies = [ dependencies = [
"askama", "askama",
"axum-core", "axum-core",
"http", "http 1.1.0",
] ]
[[package]] [[package]]
@ -193,20 +193,20 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]] [[package]]
name = "axum" name = "axum"
version = "0.6.20" version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf" checksum = "3a6c9af12842a67734c9a2e355436e5d03b22383ed60cf13cd0c18fbfe3dcbcf"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"axum-core", "axum-core",
"axum-macros", "axum-macros",
"bitflags 1.3.2",
"bytes", "bytes",
"futures-util", "futures-util",
"headers", "http 1.1.0",
"http", "http-body 1.0.0",
"http-body", "http-body-util",
"hyper", "hyper 1.3.1",
"hyper-util",
"itoa", "itoa",
"matchit", "matchit",
"memchr", "memchr",
@ -218,35 +218,40 @@ dependencies = [
"serde_json", "serde_json",
"serde_path_to_error", "serde_path_to_error",
"serde_urlencoded", "serde_urlencoded",
"sync_wrapper", "sync_wrapper 1.0.1",
"tokio", "tokio",
"tower", "tower",
"tower-layer", "tower-layer",
"tower-service", "tower-service",
"tracing",
] ]
[[package]] [[package]]
name = "axum-core" name = "axum-core"
version = "0.3.4" version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "759fa577a247914fd3f7f76d62972792636412fbfd634cd452f6a385a74d2d2c" checksum = "a15c63fd72d41492dc4f497196f5da1fb04fb7529e631d73630d1b491e47a2e3"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"bytes", "bytes",
"futures-util", "futures-util",
"http", "http 1.1.0",
"http-body", "http-body 1.0.0",
"http-body-util",
"mime", "mime",
"pin-project-lite",
"rustversion", "rustversion",
"sync_wrapper 0.1.2",
"tower-layer", "tower-layer",
"tower-service", "tower-service",
"tracing",
] ]
[[package]] [[package]]
name = "axum-extra" name = "axum-extra"
version = "0.8.0" version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ab90e7b70bea63a153137162affb6a0bce26b584c24a4c7885509783e2cf30b" checksum = "0be6ea09c9b96cb5076af0de2e383bd2bc0c18f827cf1967bdd353e0b910d733"
dependencies = [ dependencies = [
"axum", "axum",
"axum-core", "axum-core",
@ -254,24 +259,26 @@ dependencies = [
"bytes", "bytes",
"form_urlencoded", "form_urlencoded",
"futures-util", "futures-util",
"http", "headers",
"http-body", "http 1.1.0",
"http-body 1.0.0",
"http-body-util",
"mime", "mime",
"percent-encoding", "percent-encoding",
"pin-project-lite", "pin-project-lite",
"serde", "serde",
"serde_html_form", "serde_html_form",
"tokio",
"tower", "tower",
"tower-layer", "tower-layer",
"tower-service", "tower-service",
"tracing",
] ]
[[package]] [[package]]
name = "axum-macros" name = "axum-macros"
version = "0.3.8" version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdca6a10ecad987bda04e95606ef85a5417dcaac1a78455242d72e031e2b6b62" checksum = "00c055ee2d014ae5981ce1016374e8213682aa14d9bf40e48ab48b5f3ef20eaa"
dependencies = [ dependencies = [
"heck", "heck",
"proc-macro2", "proc-macro2",
@ -1583,7 +1590,7 @@ dependencies = [
"futures-core", "futures-core",
"futures-sink", "futures-sink",
"futures-util", "futures-util",
"http", "http 0.2.9",
"indexmap 1.9.3", "indexmap 1.9.3",
"slab", "slab",
"tokio", "tokio",
@ -1618,14 +1625,14 @@ dependencies = [
[[package]] [[package]]
name = "headers" name = "headers"
version = "0.3.9" version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06683b93020a07e3dbcf5f8c0f6d40080d725bea7936fc01ad345c01b97dc270" checksum = "322106e6bd0cba2d5ead589ddb8150a13d7c4217cf80d7c4f682ca994ccc6aa9"
dependencies = [ dependencies = [
"base64", "base64",
"bytes", "bytes",
"headers-core", "headers-core",
"http", "http 1.1.0",
"httpdate", "httpdate",
"mime", "mime",
"sha1", "sha1",
@ -1633,11 +1640,11 @@ dependencies = [
[[package]] [[package]]
name = "headers-core" name = "headers-core"
version = "0.2.0" version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7f66481bfee273957b1f20485a4ff3362987f85b2c236580d81b4eb7a326429" checksum = "54b4a22553d4242c49fddb9ba998a99962b5cc6f22cb5a3482bec22522403ce4"
dependencies = [ dependencies = [
"http", "http 1.1.0",
] ]
[[package]] [[package]]
@ -1699,6 +1706,17 @@ dependencies = [
"itoa", "itoa",
] ]
[[package]]
name = "http"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258"
dependencies = [
"bytes",
"fnv",
"itoa",
]
[[package]] [[package]]
name = "http-body" name = "http-body"
version = "0.4.5" version = "0.4.5"
@ -1706,7 +1724,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1"
dependencies = [ dependencies = [
"bytes", "bytes",
"http", "http 0.2.9",
"pin-project-lite",
]
[[package]]
name = "http-body"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643"
dependencies = [
"bytes",
"http 1.1.0",
]
[[package]]
name = "http-body-util"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0475f8b2ac86659c21b64320d5d653f9efe42acd2a4e560073ec61a155a34f1d"
dependencies = [
"bytes",
"futures-core",
"http 1.1.0",
"http-body 1.0.0",
"pin-project-lite", "pin-project-lite",
] ]
@ -1754,8 +1795,8 @@ dependencies = [
"futures-core", "futures-core",
"futures-util", "futures-util",
"h2", "h2",
"http", "http 0.2.9",
"http-body", "http-body 0.4.5",
"httparse", "httparse",
"httpdate", "httpdate",
"itoa", "itoa",
@ -1767,6 +1808,25 @@ dependencies = [
"want", "want",
] ]
[[package]]
name = "hyper"
version = "1.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe575dd17d0862a9a33781c8c4696a55c320909004a67a00fb286ba8b1bc496d"
dependencies = [
"bytes",
"futures-channel",
"futures-util",
"http 1.1.0",
"http-body 1.0.0",
"httparse",
"httpdate",
"itoa",
"pin-project-lite",
"smallvec",
"tokio",
]
[[package]] [[package]]
name = "hyper-rustls" name = "hyper-rustls"
version = "0.24.1" version = "0.24.1"
@ -1774,13 +1834,29 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d78e1e73ec14cf7375674f74d7dde185c8206fd9dea6fb6295e8a98098aaa97" checksum = "8d78e1e73ec14cf7375674f74d7dde185c8206fd9dea6fb6295e8a98098aaa97"
dependencies = [ dependencies = [
"futures-util", "futures-util",
"http", "http 0.2.9",
"hyper", "hyper 0.14.27",
"rustls", "rustls",
"tokio", "tokio",
"tokio-rustls", "tokio-rustls",
] ]
[[package]]
name = "hyper-util"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca38ef113da30126bbff9cd1705f9273e15d45498615d138b0c20279ac7a76aa"
dependencies = [
"bytes",
"futures-util",
"http 1.1.0",
"http-body 1.0.0",
"hyper 1.3.1",
"pin-project-lite",
"socket2 0.5.5",
"tokio",
]
[[package]] [[package]]
name = "idna" name = "idna"
version = "0.4.0" version = "0.4.0"
@ -2415,9 +2491,9 @@ dependencies = [
"futures-core", "futures-core",
"futures-util", "futures-util",
"h2", "h2",
"http", "http 0.2.9",
"http-body", "http-body 0.4.5",
"hyper", "hyper 0.14.27",
"hyper-rustls", "hyper-rustls",
"ipnet", "ipnet",
"js-sys", "js-sys",
@ -2811,9 +2887,9 @@ dependencies = [
[[package]] [[package]]
name = "smallvec" name = "smallvec"
version = "1.11.1" version = "1.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
[[package]] [[package]]
name = "socket2" name = "socket2"
@ -3127,6 +3203,12 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160"
[[package]]
name = "sync_wrapper"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394"
[[package]] [[package]]
name = "system-configuration" name = "system-configuration"
version = "0.5.1" version = "0.5.1"

View file

@ -6,9 +6,13 @@ edition = "2021"
[dependencies] [dependencies]
anyhow = "1.0.75" anyhow = "1.0.75"
askama = { version = "0.12.1", features = ["with-axum"] } askama = { version = "0.12.1", features = ["with-axum"] }
askama_axum = "0.3.0" askama_axum = "0.4.0"
axum = { version = "0.6.20", features = ["macros", "headers"] } axum = { version = "0.7.5", features = ["macros"] }
axum-extra = { version = "0.8.0", features = ["typed-routing", "query"] } axum-extra = { version = "0.9.3", features = [
"query",
"typed-routing",
"typed-header",
] }
bytes = "1.5.0" bytes = "1.5.0"
clap = { version = "4.4.6", features = ["derive", "deprecated"] } clap = { version = "4.4.6", features = ["derive", "deprecated"] }
directories = "5.0.1" directories = "5.0.1"

View file

@ -9,6 +9,7 @@ mod r#static;
use axum::{extract::DefaultBodyLimit, routing::get, Router}; use axum::{extract::DefaultBodyLimit, routing::get, Router};
use axum_extra::routing::RouterExt; use axum_extra::routing::RouterExt;
use log::info; use log::info;
use tokio::net::TcpListener;
use crate::somehow; use crate::somehow;
@ -71,9 +72,8 @@ pub async fn run(server: Server) -> somehow::Result<()> {
let addr = &server.config.web_address; let addr = &server.config.web_address;
info!("Launching web server at http://{}", addr); info!("Launching web server at http://{}", addr);
axum::Server::bind(addr) let listener = TcpListener::bind(addr).await?;
.serve(app.into_make_service()) axum::serve(listener, app).await?;
.await?;
Ok(()) Ok(())
} }

View file

@ -4,13 +4,15 @@ mod stream;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use axum::{ use axum::{
body::StreamBody, body::Body,
extract::State, extract::State,
headers::{authorization::Basic, Authorization}, http::{header, HeaderValue, StatusCode},
http::StatusCode,
http::{header, HeaderValue},
response::{IntoResponse, Response}, response::{IntoResponse, Response},
Json, TypedHeader, Json,
};
use axum_extra::{
headers::{authorization::Basic, Authorization},
TypedHeader,
}; };
use gix::{ObjectId, ThreadSafeRepository}; use gix::{ObjectId, ThreadSafeRepository};
use log::{debug, info}; use log::{debug, info};
@ -201,7 +203,7 @@ fn stream_response(repo: Arc<ThreadSafeRepository>, id: ObjectId) -> impl IntoRe
HeaderValue::from_static("attachment; filename=\"tree.tar.gz\""), HeaderValue::from_static("attachment; filename=\"tree.tar.gz\""),
), ),
], ],
StreamBody::new(stream::tar_and_gzip(repo, id)), Body::from_stream(stream::tar_and_gzip(repo, id)),
) )
} }

View file

@ -1,9 +1,11 @@
//! Verify worker basic authentication headers. //! Verify worker basic authentication headers.
use axum::{ use axum::{
headers::{authorization::Basic, Authorization},
http::{header, HeaderValue, StatusCode}, http::{header, HeaderValue, StatusCode},
response::{IntoResponse, Response}, response::{IntoResponse, Response},
};
use axum_extra::{
headers::{authorization::Basic, Authorization},
TypedHeader, TypedHeader,
}; };