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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悶 add a minimal version of mime guessing to serve_dir #461

Merged
merged 1 commit into from May 7, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Expand Up @@ -39,13 +39,14 @@ serde_json = "1.0.41"
serde_qs = "0.5.0"
async-std = { version = "1.4.0", features = ["unstable"] }
mime = "0.3.14"
cookie = { version="0.12.0", features = ["percent-encode"]}
cookie = { version = "0.12.0", features = ["percent-encode"]}
futures-core = "0.3.1"
futures = { version = "0.3.1", optional = true }
http = { version = "0.2.0", optional = true }
tokio = { version = "0.2.13", optional = true }
url = "2.1.1"
kv-log-macro = "1.0.4"
mime_guess = "2.0.3"

[dev-dependencies]
async-std = { version = "1.4.0", features = ["unstable", "attributes"] }
Expand Down
5 changes: 5 additions & 0 deletions src/server/serve_dir.rs
Expand Up @@ -69,6 +69,11 @@ impl<State> Endpoint<State> for ServeDir {
// TODO: fix related bug where async-h1 crashes on large files
let mut res = Response::new(StatusCode::Ok);
res.set_body(body);

if let Some(content_type) = mime_guess::from_path(&file_path).first() {
res = res.set_mime(content_type);
yoshuawuyts marked this conversation as resolved.
Show resolved Hide resolved
}

Ok(res)
})
}
Expand Down