From 71312435ea5f5c2afe971e621af89ea9c904fa86 Mon Sep 17 00:00:00 2001 From: Arnaud Rocher Date: Fri, 24 May 2024 18:33:16 +0000 Subject: [PATCH] fix(deps): upgrade axum --- Cargo.lock | 37 +++++++++++++++++++++++-------------- Cargo.toml | 3 +-- src/http_api.rs | 14 +++++++------- src/main.rs | 18 +++++++++++++----- 4 files changed, 44 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5e76c8a..ab8a3ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -95,18 +95,19 @@ checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "axum" -version = "0.6.20" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf" +checksum = "3a6c9af12842a67734c9a2e355436e5d03b22383ed60cf13cd0c18fbfe3dcbcf" dependencies = [ "async-trait", "axum-core", - "bitflags 1.3.2", "bytes", "futures-util", - "http 0.2.12", - "http-body 0.4.6", - "hyper 0.14.28", + "http 1.1.0", + "http-body 1.0.0", + "http-body-util", + "hyper 1.3.1", + "hyper-util", "itoa", "matchit", "memchr", @@ -117,7 +118,7 @@ dependencies = [ "serde", "serde_json", "serde_path_to_error", - "sync_wrapper", + "sync_wrapper 1.0.1", "tokio", "tower", "tower-layer", @@ -126,17 +127,20 @@ dependencies = [ [[package]] name = "axum-core" -version = "0.3.4" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "759fa577a247914fd3f7f76d62972792636412fbfd634cd452f6a385a74d2d2c" +checksum = "a15c63fd72d41492dc4f497196f5da1fb04fb7529e631d73630d1b491e47a2e3" dependencies = [ "async-trait", "bytes", "futures-util", - "http 0.2.12", - "http-body 0.4.6", + "http 1.1.0", + "http-body 1.0.0", + "http-body-util", "mime", + "pin-project-lite", "rustversion", + "sync_wrapper 0.1.2", "tower-layer", "tower-service", ] @@ -255,7 +259,6 @@ dependencies = [ "clap", "clap-verbosity-flag", "futures-util", - "hyper 0.14.28", "mockito", "mongodb", "reqwest", @@ -761,7 +764,6 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2 0.5.7", "tokio", "tower-service", "tracing", @@ -780,6 +782,7 @@ dependencies = [ "http 1.1.0", "http-body 1.0.0", "httparse", + "httpdate", "itoa", "pin-project-lite", "smallvec", @@ -1330,7 +1333,7 @@ dependencies = [ "serde", "serde_json", "serde_urlencoded", - "sync_wrapper", + "sync_wrapper 0.1.2", "tokio", "tower-service", "url", @@ -1724,6 +1727,12 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" + [[package]] name = "take_mut" version = "0.2.2" diff --git a/Cargo.toml b/Cargo.toml index 237bf6b..2e61469 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ tracing = "0.1.40" url = "2.4.1" [dependencies.axum] -version = "0.6.20" +version = "0.7.5" default-features = false features = [ "http1", "json", "tokio" ] @@ -48,6 +48,5 @@ default-features = false features = [ "ansi", "fmt", "parking_lot", "smallvec", "std" ] [dev-dependencies] -hyper = { version = "0.14.27", default-features = false } mockito = "1.2.0" tower = { version = "0.4.13", default-features = false } diff --git a/src/http_api.rs b/src/http_api.rs index 6f264d3..3ec000e 100644 --- a/src/http_api.rs +++ b/src/http_api.rs @@ -128,7 +128,7 @@ async fn centrifugo_subscribe_handler( #[cfg(test)] mod tests { - use axum::body::Body; + use axum::body::{to_bytes, Body}; use axum::http::Request; use tower::ServiceExt; @@ -215,7 +215,7 @@ mod tests { let res = app.oneshot(req).await.unwrap(); assert_eq!(res.status(), StatusCode::OK); assert_eq!(res.headers()["Content-Type"], "application/json"); - let body = hyper::body::to_bytes(res).await.unwrap(); + let body = to_bytes(res.into_body(), 1024).await.unwrap(); assert_eq!( body, r#"{"error":{"code":1000,"message":"unsupported protocol"}}"# @@ -235,7 +235,7 @@ mod tests { let res = app.oneshot(req).await.unwrap(); assert_eq!(res.status(), StatusCode::OK); assert_eq!(res.headers()["Content-Type"], "application/json"); - let body = hyper::body::to_bytes(res).await.unwrap(); + let body = to_bytes(res.into_body(), 1024).await.unwrap(); assert_eq!( body, r#"{"error":{"code":1001,"message":"unsupported encoding"}}"# @@ -255,7 +255,7 @@ mod tests { let res = app.oneshot(req).await.unwrap(); assert_eq!(res.status(), StatusCode::OK); assert_eq!(res.headers()["Content-Type"], "application/json"); - let body = hyper::body::to_bytes(res).await.unwrap(); + let body = to_bytes(res.into_body(), 1024).await.unwrap(); assert_eq!( body, r#"{"error":{"code":1002,"message":"bad channel namespace"}}"# @@ -293,7 +293,7 @@ mod tests { let res = app.oneshot(req).await.unwrap(); assert_eq!(res.status(), StatusCode::OK); assert_eq!(res.headers()["Content-Type"], "application/json"); - let body = hyper::body::to_bytes(res).await.unwrap(); + let body = to_bytes(res.into_body(), 1024).await.unwrap(); assert_eq!( body, r#"{"error":{"code":1003,"message":"internal error"}}"# @@ -317,7 +317,7 @@ mod tests { let res = app.oneshot(req).await.unwrap(); assert_eq!(res.status(), StatusCode::OK); assert_eq!(res.headers()["Content-Type"], "application/json"); - let body = hyper::body::to_bytes(res).await.unwrap(); + let body = to_bytes(res.into_body(), 1024).await.unwrap(); assert_eq!(body, r#"{"result":{"data":{}}}"#); } @@ -345,7 +345,7 @@ mod tests { let res = app.oneshot(req).await.unwrap(); assert_eq!(res.status(), StatusCode::OK); assert_eq!(res.headers()["Content-Type"], "application/json"); - let body = hyper::body::to_bytes(res).await.unwrap(); + let body = to_bytes(res.into_body(), 1024).await.unwrap(); let body = String::from_utf8(body.to_vec()).unwrap(); assert!(body.starts_with(r#"{"result":{"data":{"#)); assert!(body.contains(r#""first":9"#)); diff --git a/src/main.rs b/src/main.rs index 6593fb2..8e9f319 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,13 +1,13 @@ use std::sync::Arc; use anyhow::Context as _; -use axum::Server; use clap::Parser; use clap_verbosity_flag::{InfoLevel, Verbosity}; use futures_util::StreamExt; use signal_hook::consts::TERM_SIGNALS; use signal_hook::low_level::signal_name; use signal_hook_tokio::Signals; +use tokio::net::TcpListener; use tokio_util::sync::CancellationToken; use tracing::{error, info, info_span, instrument, Instrument}; use tracing_log::LogTracer; @@ -85,10 +85,18 @@ async fn main() -> anyhow::Result<()> { current_data_channel, }); async move { - info!(addr = %args.common.listen_address, msg = "start listening"); - if let Err(err) = Server::bind(&args.common.listen_address) - .serve(app.into_make_service()) - .with_graceful_shutdown(shutdown_token.cancelled()) + let listener = match TcpListener::bind(&args.common.listen_address).await { + Ok(listener) => { + info!(addr = %args.common.listen_address, msg = "listening"); + listener + } + Err(err) => { + error!(kind="TCP listen", %err); + return; + } + }; + if let Err(err) = axum::serve(listener, app.into_make_service()) + .with_graceful_shutdown(shutdown_token.cancelled_owned()) .await { error!(kind = "HTTP server", %err);