Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples/static-file-server, ServeDir compress not work #2059

Closed
simline opened this issue Jun 24, 2023 · 3 comments
Closed

examples/static-file-server, ServeDir compress not work #2059

simline opened this issue Jun 24, 2023 · 3 comments

Comments

@simline
Copy link

simline commented Jun 24, 2023

- [x] I have looked for existing issues (including closed) about this

Bug Report

Version

0.6.x and main branch

Platform

Linux fedora 6.2.15-200.fc37.x86_64 #1 SMP PREEMPT_DYNAMIC Thu May 11 15:56:33 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Crates

examples/static-file-server

Description

let svc = ServeDir::new("assets")

.not_found_service(ServeFile::new("assets/index.html"))

.precompressed_gzip()

.precompressed_deflate()

.precompressed_br()

;


// Should reply with gzipped file if client supports it

let request = Request::builder()

.uri("/index.html")

.header("Accept-Encoding", "gzip")

.body(Body::empty())

.unwrap();

let res = svc.clone().oneshot(request).await.unwrap();


assert_eq!(res.headers()["content-encoding"], "gzip");

assert_eq!(res.headers()["content-type"], "text/html");

got panic:

thread 'main' panicked at 'no entry found for key "content-encoding"', examples/static-file-server/src/main.rs:43:16

@jplatte
Copy link
Member

jplatte commented Jun 24, 2023

Is there an index.html.gz in your data directory? The methods you called are for serving precompressed files that already exist on disk. For compressing on the fly, use CompressionLayer.

@simline
Copy link
Author

simline commented Jun 24, 2023

@jplatte
with zip file, still not work.
But compression layer works fine.
It might be a tower-http problem, not support file without extension either, maybe there's more bug.

@jplatte
Copy link
Member

jplatte commented Jun 24, 2023

Not .zip, .gz as created by gzip. Anyways, please open an issue or maybe a discussion on tower-http if you have trouble using it. axum isn't really relevant here.

@jplatte jplatte closed this as not planned Won't fix, can't repro, duplicate, stale Jun 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants