From 5ef8dc823eabe4cd95054647d9a712f09fd7f2d5 Mon Sep 17 00:00:00 2001 From: tottoto Date: Sat, 9 Mar 2024 00:54:24 +0900 Subject: [PATCH 1/2] validate-request: remove Body trait bound from response body --- tower-http/Cargo.toml | 2 +- tower-http/src/validate_request.rs | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/tower-http/Cargo.toml b/tower-http/Cargo.toml index baf8630b..f3b43fb3 100644 --- a/tower-http/Cargo.toml +++ b/tower-http/Cargo.toml @@ -105,7 +105,7 @@ set-status = [] timeout = ["dep:http-body", "tokio/time"] trace = ["dep:http-body", "tracing"] util = ["tower"] -validate-request = ["dep:http-body", "mime"] +validate-request = ["mime"] compression-br = ["async-compression/brotli", "futures-core", "dep:http-body", "tokio-util", "tokio"] compression-deflate = ["async-compression/zlib", "futures-core", "dep:http-body", "tokio-util", "tokio"] diff --git a/tower-http/src/validate_request.rs b/tower-http/src/validate_request.rs index 327266af..efb301e4 100644 --- a/tower-http/src/validate_request.rs +++ b/tower-http/src/validate_request.rs @@ -117,7 +117,6 @@ //! ``` use http::{header, Request, Response, StatusCode}; -use http_body::Body; use mime::{Mime, MimeIter}; use pin_project_lite::pin_project; use std::{ @@ -163,7 +162,7 @@ impl ValidateRequestHeaderLayer> { /// [`Accept`]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept pub fn accept(value: &str) -> Self where - ResBody: Body + Default, + ResBody: Default, { Self::custom(AcceptHeader::new(value)) } @@ -215,7 +214,7 @@ impl ValidateRequestHeader> { /// See `AcceptHeader::new` for when this method panics. pub fn accept(inner: S, value: &str) -> Self where - ResBody: Body + Default, + ResBody: Default, { Self::custom(inner, AcceptHeader::new(value)) } @@ -339,7 +338,7 @@ impl AcceptHeader { /// Panics if `header_value` is not in the form: `type/subtype`, such as `application/json` fn new(header_value: &str) -> Self where - ResBody: Body + Default, + ResBody: Default, { Self { header_value: Arc::new( @@ -371,7 +370,7 @@ impl fmt::Debug for AcceptHeader { impl ValidateRequest for AcceptHeader where - ResBody: Body + Default, + ResBody: Default, { type ResponseBody = ResBody; From 9851dd6ea7bf8266e655954c062e02b810808c19 Mon Sep 17 00:00:00 2001 From: tottoto Date: Sat, 9 Mar 2024 00:59:21 +0900 Subject: [PATCH 2/2] auth: remove Body trait bound from response body --- tower-http/Cargo.toml | 2 +- tower-http/src/auth/require_authorization.rs | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/tower-http/Cargo.toml b/tower-http/Cargo.toml index f3b43fb3..abacc96e 100644 --- a/tower-http/Cargo.toml +++ b/tower-http/Cargo.toml @@ -86,7 +86,7 @@ full = [ ] add-extension = [] -auth = ["base64", "dep:http-body", "validate-request"] +auth = ["base64", "validate-request"] catch-panic = ["tracing", "futures-util/std", "dep:http-body", "dep:http-body-util"] cors = [] follow-redirect = ["futures-util", "dep:http-body", "iri-string", "tower/util"] diff --git a/tower-http/src/auth/require_authorization.rs b/tower-http/src/auth/require_authorization.rs index d5c9508f..7aa1a87f 100644 --- a/tower-http/src/auth/require_authorization.rs +++ b/tower-http/src/auth/require_authorization.rs @@ -60,7 +60,6 @@ use http::{ header::{self, HeaderValue}, Request, Response, StatusCode, }; -use http_body::Body; use std::{fmt, marker::PhantomData}; const BASE64: base64::engine::GeneralPurpose = base64::engine::general_purpose::STANDARD; @@ -75,7 +74,7 @@ impl ValidateRequestHeader> { /// with this method. However use of HTTPS/TLS is not enforced by this middleware. pub fn basic(inner: S, username: &str, value: &str) -> Self where - ResBody: Body + Default, + ResBody: Default, { Self::custom(inner, Basic::new(username, value)) } @@ -91,7 +90,7 @@ impl ValidateRequestHeaderLayer> { /// with this method. However use of HTTPS/TLS is not enforced by this middleware. pub fn basic(username: &str, password: &str) -> Self where - ResBody: Body + Default, + ResBody: Default, { Self::custom(Basic::new(username, password)) } @@ -107,7 +106,7 @@ impl ValidateRequestHeader> { /// Panics if the token is not a valid [`HeaderValue`]. pub fn bearer(inner: S, token: &str) -> Self where - ResBody: Body + Default, + ResBody: Default, { Self::custom(inner, Bearer::new(token)) } @@ -123,7 +122,7 @@ impl ValidateRequestHeaderLayer> { /// Panics if the token is not a valid [`HeaderValue`]. pub fn bearer(token: &str) -> Self where - ResBody: Body + Default, + ResBody: Default, { Self::custom(Bearer::new(token)) } @@ -140,7 +139,7 @@ pub struct Bearer { impl Bearer { fn new(token: &str) -> Self where - ResBody: Body + Default, + ResBody: Default, { Self { header_value: format!("Bearer {}", token) @@ -170,7 +169,7 @@ impl fmt::Debug for Bearer { impl ValidateRequest for Bearer where - ResBody: Body + Default, + ResBody: Default, { type ResponseBody = ResBody; @@ -197,7 +196,7 @@ pub struct Basic { impl Basic { fn new(username: &str, password: &str) -> Self where - ResBody: Body + Default, + ResBody: Default, { let encoded = BASE64.encode(format!("{}:{}", username, password)); let header_value = format!("Basic {}", encoded).parse().unwrap(); @@ -227,7 +226,7 @@ impl fmt::Debug for Basic { impl ValidateRequest for Basic where - ResBody: Body + Default, + ResBody: Default, { type ResponseBody = ResBody;