diff --git a/Cargo.lock b/Cargo.lock index 981d09853d..3b94a06ea1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2038,9 +2038,11 @@ dependencies = [ name = "linkerd-metrics" version = "0.1.0" dependencies = [ + "bytes", "deflate", "http 1.2.0", "http-body", + "http-body-util", "hyper", "linkerd-http-box", "linkerd-stack", diff --git a/linkerd/metrics/Cargo.toml b/linkerd/metrics/Cargo.toml index 08d33de55b..fdaa0f98d7 100644 --- a/linkerd/metrics/Cargo.toml +++ b/linkerd/metrics/Cargo.toml @@ -13,9 +13,11 @@ stack = ["linkerd-stack"] test_util = [] [dependencies] +bytes = { workspace = true } deflate = { version = "1", features = ["gzip"] } http = { workspace = true } http-body = { workspace = true } +http-body-util = { workspace = true } hyper = { workspace = true, features = ["http1", "http2"] } linkerd-http-box = { path = "../http/box" } linkerd-stack = { path = "../stack", optional = true } diff --git a/linkerd/metrics/src/serve.rs b/linkerd/metrics/src/serve.rs index 045e5d5015..ad64501c11 100644 --- a/linkerd/metrics/src/serve.rs +++ b/linkerd/metrics/src/serve.rs @@ -1,5 +1,5 @@ +use bytes::Bytes; use deflate::{write::GzEncoder, CompressionOptions}; -use linkerd_http_box::BoxBody; use std::io::Write; use tracing::trace; @@ -33,7 +33,10 @@ impl Serve { } impl Serve { - pub fn serve(&self, req: http::Request) -> std::io::Result> { + pub fn serve( + &self, + req: http::Request, + ) -> std::io::Result>> { if Self::is_gzip(&req) { trace!("gzipping metrics"); let mut writer = GzEncoder::new(Vec::::new(), CompressionOptions::fast()); @@ -41,14 +44,16 @@ impl Serve { Ok(http::Response::builder() .header(http::header::CONTENT_ENCODING, "gzip") .header(http::header::CONTENT_TYPE, "text/plain") - .body(BoxBody::new(hyper::Body::from(writer.finish()?))) + .body(http_body_util::Full::from( + writer.finish().map(Bytes::from)?, + )) .expect("Response must be valid")) } else { let mut writer = Vec::::new(); write!(&mut writer, "{}", self.metrics.as_display())?; Ok(http::Response::builder() .header(http::header::CONTENT_TYPE, "text/plain") - .body(BoxBody::new(hyper::Body::from(writer))) + .body(http_body_util::Full::from(Bytes::from(writer))) .expect("Response must be valid")) } }