Skip to content

Commit

Permalink
Add test for precompressed fallback in case of no extension in origin…
Browse files Browse the repository at this point in the history
…al path
  • Loading branch information
SvizelPritula committed Sep 3, 2024
1 parent be59a63 commit 69f5ca0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions test-files/extensionless_precompressed_missing
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Content.
21 changes: 21 additions & 0 deletions tower-http/src/services/fs/serve_dir/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,27 @@ async fn precompressed_without_extension() {
assert!(decompressed.starts_with("Content."));
}

#[tokio::test]
async fn missing_precompressed_without_extension_fallbacks_to_uncompressed() {
let svc = ServeDir::new("../test-files").precompressed_gzip();

let request = Request::builder()
.uri("/extensionless_precompressed_missing")
.header("Accept-Encoding", "gzip")
.body(Body::empty())
.unwrap();
let res = svc.oneshot(request).await.unwrap();

assert_eq!(res.status(), StatusCode::OK);

assert_eq!(res.headers()["content-type"], "application/octet-stream");
assert!(res.headers().get("content-encoding").is_none());

let body = res.into_body().collect().await.unwrap().to_bytes();
let body = String::from_utf8(body.to_vec()).unwrap();
assert!(body.starts_with("Content."));
}

#[tokio::test]
async fn access_to_sub_dirs() {
let svc = ServeDir::new("..");
Expand Down

0 comments on commit 69f5ca0

Please sign in to comment.