feat(actix-files): support multiple fallback directory indexes#3699
feat(actix-files): support multiple fallback directory indexes#3699imgurbot12 wants to merge 2 commits into
Conversation
|
Is it possible to re-run the jobs on this one? It looks like some unrelated h2 unit-test timed out after getting stuck for almost an hour lol. |
|
Triggered 👍 Notes: |
|
Thanks!
Fair enough I guess, I'm using my fork of actix-web until all of my PRs end up merged to support that project I mentioned, though I'm not sure what you mean by "best form". |
Samielakkad
left a comment
There was a problem hiding this comment.
The multiple-index API is useful, but the lookup path probably wants to avoid Path::exists() here:
let index = this
.indexes
.iter()
.map(|i| path.join(i))
.find(|p| p.exists());Two reasons:
exists()is a synchronous filesystem stat inside the async service path.- More importantly, it changes fallback behavior. If the first configured index path exists but
NamedFile::open_asyncfails because it is unreadable, a directory, races with deletion, etc., the service handles that error immediately and never tries the next configured index. With multiple fallbacks, I would expect it to attemptindex.html, thenindex.htm, etc. until one actually opens.
A cleaner shape may be to iterate the configured names and call NamedFile::open_async(path.join(index)).await for each, returning the first successful open and only falling back to listing/default/error after all configured index files fail with not-found-style errors.
PR Type
Feature / Refactor
PR Checklist
Overview
This modification allows for the support of multiple index file fallbacks, similar to apache2/nginx.
Eg.
[index.actix.html, index.html, index.txt, ...]The implementation appends the indexes to a vector rather than the default option, and is configured
using the existing
Files::index_filewhich can be called multiple times to append each entry.This design should avoid any breaking changes as the default behavior of just calling it once results in the same functionality before the modification.
This PR supports a personal project of mine attempting to implement an caddy/apache-style reverse-proxy service. Supported by a bunch of services I've written recently.
Thank you :)