Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 69f5ca0

Browse files
committedSep 3, 2024·
Add test for precompressed fallback in case of no extension in original path
1 parent be59a63 commit 69f5ca0

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Content.

‎tower-http/src/services/fs/serve_dir/tests.rs

+21
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,27 @@ async fn precompressed_without_extension() {
275275
assert!(decompressed.starts_with("Content."));
276276
}
277277

278+
#[tokio::test]
279+
async fn missing_precompressed_without_extension_fallbacks_to_uncompressed() {
280+
let svc = ServeDir::new("../test-files").precompressed_gzip();
281+
282+
let request = Request::builder()
283+
.uri("/extensionless_precompressed_missing")
284+
.header("Accept-Encoding", "gzip")
285+
.body(Body::empty())
286+
.unwrap();
287+
let res = svc.oneshot(request).await.unwrap();
288+
289+
assert_eq!(res.status(), StatusCode::OK);
290+
291+
assert_eq!(res.headers()["content-type"], "application/octet-stream");
292+
assert!(res.headers().get("content-encoding").is_none());
293+
294+
let body = res.into_body().collect().await.unwrap().to_bytes();
295+
let body = String::from_utf8(body.to_vec()).unwrap();
296+
assert!(body.starts_with("Content."));
297+
}
298+
278299
#[tokio::test]
279300
async fn access_to_sub_dirs() {
280301
let svc = ServeDir::new("..");

0 commit comments

Comments
 (0)
Please sign in to comment.