From e621000369c320b6c720261127f151cb0d760ca6 Mon Sep 17 00:00:00 2001 From: NickAc <32451103+NickAcPT@users.noreply.github.com> Date: Sun, 15 Sep 2024 13:41:22 +0100 Subject: [PATCH] Bump Tower version to 0.5 --- nmsr-aas/Cargo.toml | 39 +++++++++++++++++++++---------- nmsr-aas/src/utils/http_client.rs | 13 +++++------ nmsr-aas/src/utils/png.rs | 2 +- 3 files changed, 34 insertions(+), 20 deletions(-) diff --git a/nmsr-aas/Cargo.toml b/nmsr-aas/Cargo.toml index c132c0d..ac0a4ff 100644 --- a/nmsr-aas/Cargo.toml +++ b/nmsr-aas/Cargo.toml @@ -18,13 +18,8 @@ nmsr-rendering-blockbench-model-generator-experiment = { path = "../utils/nmsr-r ears-rs = { workspace = true } anyhow = { workspace = true } -axum = { version = "0.7", features = [ - "macros", - "tokio" -] } -axum-extra = { version = "0.9", features = [ - "multipart", -] } +axum = { version = "0.7", features = ["macros", "tokio"] } +axum-extra = { version = "0.9", features = ["multipart"] } http-body-util = "0.1" # async-trait - Async trait support because Rust is bad at async @@ -45,12 +40,25 @@ base64 = "0.22" # Hyper - HTTP client hyper = { version = "1.4", features = ["client"] } -hyper-util = { version = "0.1", features = ["client", "client-legacy", "http1", "http2", "server-auto", "tokio"] } +hyper-util = { version = "0.1", features = [ + "client", + "client-legacy", + "http1", + "http2", + "server-auto", + "tokio", +] } hyper-tls = "0.6" url = "2.5" # Tokio - Async runtime -tokio = { workspace = true, features = ["macros", "fs", "sync", "signal", "rt-multi-thread"] } +tokio = { workspace = true, features = [ + "macros", + "fs", + "sync", + "signal", + "rt-multi-thread", +] } # async-scoped - Scoped async tasks async-scoped = { version = "0.9", features = ["use-tokio"] } @@ -83,8 +91,15 @@ thiserror = { workspace = true } derive_more = { workspace = true } # Tower - Service framework -tower = { version = "0.4", features = ["limit", "timeout", "retry"] } -tower-http = { version = "0.5", features = ["full"] } +tower = { version = "0.5", features = ["buffer", "limit", "timeout", "retry"] } +tower-http = { version = "0.5", features = [ + "set-header", + "trace", + "request-id", + "cors", + "normalize-path", + "fs", +] } http = "1.1" # symlink - Symbolic link library (because Rust's standard library doesn't handle that properly for us) @@ -112,4 +127,4 @@ default = [] ears = [ "nmsr-rendering/ears", "nmsr-rendering-blockbench-model-generator-experiment/ears", -] \ No newline at end of file +] diff --git a/nmsr-aas/src/utils/http_client.rs b/nmsr-aas/src/utils/http_client.rs index 6dd26ec..1b58171 100644 --- a/nmsr-aas/src/utils/http_client.rs +++ b/nmsr-aas/src/utils/http_client.rs @@ -52,7 +52,7 @@ pub(crate) type NmsrTraceLayer = Trace< >; pub struct NmsrHttpClient { - inner: Buffer>>, Request>, + inner: Buffer, >> as Service>>::Future>, } impl NmsrHttpClient { @@ -150,16 +150,15 @@ impl MojankRetryPolicy { } impl Policy, Res, P> for MojankRetryPolicy { - type Future = Ready; + type Future = Ready<()>; - fn retry(&self, _req: &Request, result: Result<&Res, &P>) -> Option { + fn retry(&mut self, _req: &mut Request, result: &mut Result) -> Option { match result { Ok(_) => None, Err(_) => { if self.attempts > 0 { - Some(ready(Self { - attempts: self.attempts - 1, - })) + self.attempts -= 1; + Some(ready(())) } else { None } @@ -167,7 +166,7 @@ impl Policy, Res, P> for MojankRetryPolicy { } } - fn clone_request(&self, req: &Request) -> Option> { + fn clone_request(&mut self, req: &Request) -> Option> { let method = req.method().clone(); let uri = req.uri().clone(); diff --git a/nmsr-aas/src/utils/png.rs b/nmsr-aas/src/utils/png.rs index c6c300c..fc3d362 100644 --- a/nmsr-aas/src/utils/png.rs +++ b/nmsr-aas/src/utils/png.rs @@ -1,7 +1,7 @@ use image::{codecs::png::PngEncoder, ImageEncoder}; use tracing::trace_span; -use crate::error::{ExplainableExt, NMSRaaSError, Result}; +use crate::error::{NMSRaaSError, Result}; pub(crate) fn create_png_from_bytes((width, height): (u32, u32), bytes: &[u8]) -> Result> { let mut out = Vec::new();