diff --git a/tower-http/src/compression/future.rs b/tower-http/src/compression/future.rs index dbe2ab24..c38ecb03 100644 --- a/tower-http/src/compression/future.rs +++ b/tower-http/src/compression/future.rs @@ -36,7 +36,6 @@ where { type Output = Result>, E>; - #[allow(unreachable_code, unused_mut, unused_variables, unreachable_patterns)] fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { let res = ready!(self.as_mut().project().inner.poll(cx)?); @@ -55,7 +54,7 @@ where } let body = match (should_compress, self.encoding) { - // if compression is _not_ support or the client doesn't accept it + // if compression is _not_ supported or the client doesn't accept it (false, _) | (_, Encoding::Identity) => { return Poll::Ready(Ok(Response::from_parts( parts, @@ -80,6 +79,7 @@ where CompressionBody::new(BodyInner::zstd(WrapBody::new(body, self.quality))) } #[cfg(feature = "fs")] + #[allow(unreachable_patterns)] (true, _) => { // This should never happen because the `AcceptEncoding` struct which is used to determine // `self.encoding` will only enable the different compression algorithms if the diff --git a/tower-http/src/compression_utils.rs b/tower-http/src/compression_utils.rs index 74538a62..01aabc05 100644 --- a/tower-http/src/compression_utils.rs +++ b/tower-http/src/compression_utils.rs @@ -71,49 +71,37 @@ impl SupportedEncodings for AcceptEncoding { #[allow(dead_code)] fn gzip(&self) -> bool { #[cfg(any(feature = "decompression-gzip", feature = "compression-gzip"))] - { - self.gzip - } + return self.gzip; + #[cfg(not(any(feature = "decompression-gzip", feature = "compression-gzip")))] - { - false - } + return false; } #[allow(dead_code)] fn deflate(&self) -> bool { #[cfg(any(feature = "decompression-deflate", feature = "compression-deflate"))] - { - self.deflate - } + return self.deflate; + #[cfg(not(any(feature = "decompression-deflate", feature = "compression-deflate")))] - { - false - } + return false; } #[allow(dead_code)] fn br(&self) -> bool { #[cfg(any(feature = "decompression-br", feature = "compression-br"))] - { - self.br - } + return self.br; + #[cfg(not(any(feature = "decompression-br", feature = "compression-br")))] - { - false - } + return false; } #[allow(dead_code)] fn zstd(&self) -> bool { #[cfg(any(feature = "decompression-zstd", feature = "compression-zstd"))] - { - self.zstd - } + return self.zstd; + #[cfg(not(any(feature = "decompression-zstd", feature = "compression-zstd")))] - { - false - } + return false; } } @@ -200,35 +188,32 @@ where let mut this = self.project(); let mut buf = BytesMut::new(); if !*this.read_all_data { - match tokio_util::io::poll_read_buf(this.read.as_mut(), cx, &mut buf) { - Poll::Ready(result) => { - match result { - Ok(read) => { - if read == 0 { - *this.read_all_data = true; - } else { - return Poll::Ready(Some(Ok(Frame::data(buf.freeze())))); - } - } - Err(err) => { - let body_error: Option = M::get_pin_mut(this.read) - .get_pin_mut() - .project() - .error - .take(); - - if let Some(body_error) = body_error { - return Poll::Ready(Some(Err(body_error.into()))); - } else if err.raw_os_error() == Some(SENTINEL_ERROR_CODE) { - // SENTINEL_ERROR_CODE only gets used when storing an underlying body error - unreachable!() - } else { - return Poll::Ready(Some(Err(err.into()))); - } - } + let result = tokio_util::io::poll_read_buf(this.read.as_mut(), cx, &mut buf); + + match ready!(result) { + Ok(0) => { + *this.read_all_data = true; + } + Ok(_) => { + return Poll::Ready(Some(Ok(Frame::data(buf.freeze())))); + } + Err(err) => { + let body_error: Option = M::get_pin_mut(this.read) + .get_pin_mut() + .project() + .error + .take(); + + if let Some(body_error) = body_error { + return Poll::Ready(Some(Err(body_error.into()))); + } else if err.raw_os_error() == Some(SENTINEL_ERROR_CODE) { + // SENTINEL_ERROR_CODE only gets used when storing + // an underlying body error + unreachable!() + } else { + return Poll::Ready(Some(Err(err.into()))); } } - Poll::Pending => return Poll::Pending, } } diff --git a/tower-http/src/cors/allow_origin.rs b/tower-http/src/cors/allow_origin.rs index 7b8ce4c5..3d7a7f3e 100644 --- a/tower-http/src/cors/allow_origin.rs +++ b/tower-http/src/cors/allow_origin.rs @@ -51,11 +51,14 @@ impl AllowOrigin { I: IntoIterator, { let origins = origins.into_iter().collect::>(); - if origins.iter().any(|o| o == WILDCARD) { - panic!("Wildcard origin (`*`) cannot be passed to `AllowOrigin::list`. Use `AllowOrigin::any()` instead"); - } else { - Self(OriginInner::List(origins)) + if origins.contains(&WILDCARD) { + panic!( + "Wildcard origin (`*`) cannot be passed to `AllowOrigin::list`. \ + Use `AllowOrigin::any()` instead" + ); } + + Self(OriginInner::List(origins)) } /// Set the allowed origins from a predicate diff --git a/tower-http/src/cors/vary.rs b/tower-http/src/cors/vary.rs index af7697bd..1ed7e672 100644 --- a/tower-http/src/cors/vary.rs +++ b/tower-http/src/cors/vary.rs @@ -28,7 +28,7 @@ impl Vary { pub(super) fn to_header(&self) -> Option<(HeaderName, HeaderValue)> { let values = &self.0; - let mut res = values.get(0)?.as_bytes().to_owned(); + let mut res = values.first()?.as_bytes().to_owned(); for val in &values[1..] { res.extend_from_slice(b", "); res.extend_from_slice(val.as_bytes()); diff --git a/tower-http/src/trace/mod.rs b/tower-http/src/trace/mod.rs index 0b57a18d..65734a42 100644 --- a/tower-http/src/trace/mod.rs +++ b/tower-http/src/trace/mod.rs @@ -516,7 +516,7 @@ mod tests { tracing::info_span!("test-span", foo = tracing::field::Empty) }) .on_request(|_req: &Request, span: &Span| { - span.record("foo", 42); + span.record("foo", &42); ON_REQUEST_COUNT.fetch_add(1, Ordering::SeqCst); }) .on_response(|_res: &Response, _latency: Duration, _span: &Span| {