-
Notifications
You must be signed in to change notification settings - Fork 189
Add ServeFile
and ServeDir
#45
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
Conversation
In the future we'll also have `ServeDir` so makes sense for these to live in the same module. Also added a test for `ServeFile`.
So it can be used by the upcoming `ServeFile`
@tesaguri Is this something you would be up for reviewing? |
if append_index_html_on_directories { | ||
let is_dir = tokio::fs::metadata(full_path.clone()) | ||
.await | ||
.map(|m| m.is_dir()) | ||
.unwrap_or(false); | ||
|
||
if is_dir { | ||
full_path.push("index.html"); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the path points to a directory and has no trailing slash, the service should redirect to a URI with a trailing slash.
Suppose that there is ${base}/foo/index.html
with a relative URI like <script src="script.js"></script>
. When a user agent requests /foo/
, the URI script.js
resolves to /foo/script.js
as expected. But when it requests /foo
, script.js
resolves to /script.js
, which is not the desired behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh thats a good point. Didn't consider that. Fixed in 467dd06
Co-authored-by: Daiki Mizukami <[email protected]>
This way we can change the actual type without breaking changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM just one question
Service that serves a file and guesses the mime type with https://crates.io/crates/mime_guess.