Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions tower-http/src/compression/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,14 @@ where
},
}
}

fn size_hint(&self) -> http_body::SizeHint {
if let BodyInner::Identity { inner } = &self.inner {
inner.size_hint()
} else {
http_body::SizeHint::new()
}
}
}

#[cfg(feature = "compression-gzip")]
Expand Down
13 changes: 13 additions & 0 deletions tower-http/src/compression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ mod tests {
ACCEPT_ENCODING, ACCEPT_RANGES, CONTENT_ENCODING, CONTENT_RANGE, CONTENT_TYPE, RANGE,
};
use http::{HeaderMap, HeaderName, HeaderValue, Request, Response};
use http_body::Body as _;
use http_body_util::BodyExt;
use std::convert::Infallible;
use std::io::Read;
Expand Down Expand Up @@ -495,4 +496,16 @@ mod tests {
assert_eq!(headers[CONTENT_ENCODING], "gzip");
assert_eq!(decompressed, "Hello, World!");
}

#[tokio::test]
async fn size_hint_identity() {
let msg = "Hello, world!";
let svc = service_fn(|_| async { Ok::<_, std::io::Error>(Response::new(Body::from(msg))) });
let mut svc = Compression::new(svc);

let req = Request::new(Body::empty());
let res = svc.ready().await.unwrap().call(req).await.unwrap();
let body = res.into_body();
assert_eq!(body.size_hint().exact().unwrap(), msg.len() as u64);
}
}
Loading