Radish alpha
r
Radicle web interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
httpd: Update axum and hyper dependency
Sebastian Martinez committed 2 years ago
commit 4c16c2724ff0d970e9470dc7d30bfb4ebbdee0ed
parent 66369f98d9cc2b7b7b3ec413a33f20c6cdacedf8
4 files changed +17 -13
modified radicle-httpd/Cargo.toml
@@ -16,14 +16,14 @@ logfmt = [

[dependencies]
anyhow = { version = "1" }
-
axum = { version = "0.6.7", default-features = false, features = ["headers", "json", "query", "tokio"] }
-
axum-auth = { version= "0.4.0", default-features = false, features = ["auth-bearer"] }
+
axum = { version = "0.7.2", default-features = false, features = ["json", "query", "tokio", "http1"] }
+
axum-auth = { version= "0.7.0", default-features = false, features = ["auth-bearer"] }
axum-server = { version = "0.5.1", default-features = false }
base64 = "0.21.3"
chrono = { version = "0.4.22", default-features = false, features = ["clock"] }
fastrand = { version = "2.0.0" }
flate2 = { version = "1" }
-
hyper = { version = "0.14.17", default-features = false }
+
hyper = { version = "1.0.1", default-features = false }
lexopt = { version = "0.2.1" }
lru = { version = "0.11.0" }
nonempty = { version = "0.8.1", features = ["serialize"] }
@@ -33,7 +33,7 @@ serde_json = { version = "1", features = ["preserve_order"] }
thiserror = { version = "1" }
time = { version = "0.3.17", features = ["parsing", "serde"] }
tokio = { version = "1.21", default-features = false, features = ["macros", "rt-multi-thread"] }
-
tower-http = { version = "0.3.4", default-features = false, features = ["trace", "cors", "set-header"] }
+
tower-http = { version = "0.5", default-features = false, features = ["trace", "cors", "set-header"] }
tracing = { version = "0.1.37", default-features = false, features = ["std", "log"] }
tracing-logfmt = { version = "0.2", optional = true }
tracing-subscriber = { version = "0.3", default-features = false, features = ["std", "ansi", "fmt"] }
@@ -50,7 +50,7 @@ path = "../radicle-term"
path = "../radicle-cli"

[dev-dependencies]
-
hyper = { version = "0.14.17", default-features = false, features = ["client"] }
+
hyper = { version = "1.0.1", default-features = false, features = ["client"] }
pretty_assertions = { version = "1.3.0" }
radicle-cli = { path = "../radicle-cli" }
radicle-crypto = { path = "../radicle-crypto", features = ["test"] }
modified radicle-httpd/src/lib.rs
@@ -13,10 +13,11 @@ use std::sync::Arc;
use std::time::Duration;

use anyhow::Context as _;
-
use axum::body::{Body, BoxBody, HttpBody};
+
use axum::body::{Body, HttpBody};
use axum::http::{Request, Response};
use axum::middleware;
use axum::Router;
+
use tokio::net::TcpListener;
use tower_http::trace::TraceLayer;
use tracing::Span;

@@ -54,9 +55,9 @@ pub async fn run(options: Options) -> anyhow::Result<()> {

    tracing::info!("{}", str::from_utf8(&git_version)?.trim());

-
    let listen = options.listen;
+
    let listener = TcpListener::bind(options.listen).await?;

-
    tracing::info!("listening on http://{}", listen);
+
    tracing::info!("listening on http://{}", options.listen);

    let profile = Profile::load()?;
    let request_id = RequestId::new();
@@ -72,7 +73,7 @@ pub async fn run(options: Options) -> anyhow::Result<()> {
                    tracing::info_span!("request", id = %request_id.clone().next())
                })
                .on_response(
-
                    |response: &Response<BoxBody>, latency: Duration, _span: &Span| {
+
                    |response: &Response<Body>, latency: Duration, _span: &Span| {
                        if let Some(info) = response.extensions().get::<TracingInfo>() {
                            tracing::info!(
                                "{} \"{} {} {:?}\" {} {:?} {}",
@@ -100,8 +101,7 @@ pub async fn run(options: Options) -> anyhow::Result<()> {
        )
        .into_make_service_with_connect_info::<SocketAddr>();

-
    axum::Server::bind(&listen)
-
        .serve(app)
+
    axum::serve(listener, app)
        .await
        .map_err(anyhow::Error::from)
}
modified radicle-httpd/src/test.rs
@@ -381,6 +381,8 @@ impl Response {
    }

    pub async fn body(self) -> Bytes {
-
        hyper::body::to_bytes(self.0.into_body()).await.unwrap()
+
        axum::body::to_bytes(self.0.into_body(), usize::MAX)
+
            .await
+
            .unwrap()
    }
}
modified radicle-httpd/src/tracing_extra.rs
@@ -3,6 +3,7 @@ use std::net::SocketAddr;
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::Arc;

+
use axum::body::Body;
use axum::extract::ConnectInfo;
use axum::http::Request;
use axum::middleware::Next;
@@ -25,6 +26,7 @@ impl RequestId {
    }
}

+
#[derive(Clone)]
pub struct TracingInfo {
    pub connect_info: ConnectInfo<SocketAddr>,
    pub method: Method,
@@ -45,7 +47,7 @@ impl fmt::Display for ColoredStatus {
    }
}

-
pub async fn tracing_middleware<B>(request: Request<B>, next: Next<B>) -> impl IntoResponse {
+
pub async fn tracing_middleware(request: Request<Body>, next: Next) -> impl IntoResponse {
    let connect_info = *request
        .extensions()
        .get::<ConnectInfo<std::net::SocketAddr>>()