Skip to content

Commit

Permalink
fix(deps): upgrade axum
Browse files Browse the repository at this point in the history
  • Loading branch information
cailloumajor committed May 24, 2024
1 parent cc25d8b commit 7131243
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 28 deletions.
37 changes: 23 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]

Expand Down Expand Up @@ -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 }
14 changes: 7 additions & 7 deletions src/http_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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"}}"#
Expand All @@ -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"}}"#
Expand All @@ -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"}}"#
Expand Down Expand Up @@ -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"}}"#
Expand All @@ -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":{}}}"#);
}

Expand Down Expand Up @@ -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"#));
Expand Down
18 changes: 13 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 7131243

Please sign in to comment.