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

Fix EmbeddedFilesEndpoint not working for index.html in subdirectories #825

Merged
merged 1 commit into from
Jul 27, 2024

Conversation

czy-29
Copy link
Contributor

@czy-29 czy-29 commented May 30, 2024

Close #824


This is a simple fix of this bug, which is more suitable as a default behavior of EmbeddedFilesEndpoint.

Its basic logic is:
First: let path = req.uri().path().trim_start_matches('/');
Then if path is empty, and req.original_uri().path() does not end with '/', add '/' to the original uri path and redirect.
Otherwise, if req.original_uri().path() ends with '/', add index.html to path and call EmbeddedFileEndpoint.
Otherwise check if the file pointed to path exists, and if so, call EmbeddedFileEndpoint directly.
Otherwise, add /index.html and check if the file exists. If it does, add '/' to the original uri path and redirect.
Otherwise, call the EmbeddedFileEndpoint to return an appropriate 404.

However, in the long run, EmbeddedFilesEndpoint should have the same interface and behavior as StaticFilesEndpoint to ensure the consistency of the framework API, while also providing more customization of static resource behavior.

This fix only provides a more reasonable and consistent default behavior without introducing an API Breaking Change.


这是对这个bug的一个简易修复,比较适合作为EmbeddedFilesEndpoint的一个默认行为。

其基本逻辑是:
首先:let path = req.uri().path().trim_start_matches('/');
然后如果path为空,且req.original_uri().path()不以'/'结尾,则给original uri path加上'/'之后重定向。
否则如果req.original_uri().path()以'/'结尾,则给pathindex.html然后调用EmbeddedFileEndpoint
否则检查path指向的文件是否存在,如果存在则直接调用EmbeddedFileEndpoint
否则加上/index.html之后再看看文件是否存在,存在则给original uri path加上'/'之后重定向。
否则直接调用EmbeddedFileEndpoint以返回合适的404。

但是长期来看,EmbeddedFilesEndpoint应当具备与StaticFilesEndpoint相同的接口与行为,以保证框架API的一致性,同时也会提供对静态资源行为的更多定制性。

本修复只是在不引入API Breaking Change的前提下,提供了一个更合理且更一致的默认行为。

@sunli829
Copy link
Collaborator

thanks

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

Successfully merging this pull request may close these issues.

EmbeddedFilesEndpoint not working for index.html in subdirectory
2 participants