-
Notifications
You must be signed in to change notification settings - Fork 18k
net/http: http.FileServer goes into infinite redirect loop when root is a file #63769
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
Comments
cc @neild |
The problem is caused by the fact that the This should be trivial to fix, I would be more than happy to submit a pull request for this issue. |
Note, the current implementation of ServeFileFS will return the file when using it as root. |
The http.FileSystem interface predates fs.FS and might not be 100% compatible in some cases, that is why ServeFileFS works as expected, been a newer api. Having this routine enter an infinite redirect loop is not cool, and appears to be a bug that should be addressed properly. |
It is unclear to me what should happen if http.Dir is invoked with a normal file as argument, and I could not find any tests or documentation around it to back it up. All the occurrences of http.Dir in the codebase use a directory as parameter. Is that right to assume it is undefined behavior calling I'll send a CL shortly that allows a normal file to be served as well as fixing the redirect loop, but I'm not sure if that is something it should support, or if we should error out at some point saying that we need a real directory. Either way I think we should fix the redirect loop since it affects 1.20, 1.21 and tip. |
Change https://go.dev/cl/538719 mentions this issue: |
The reason why For Does it matter? Not sure. |
@neild @bcmills I'm not quite sure what should be the path forward to fix this but I would like to merge the fix before the freeze. I believe we have two choices:
I'm inclined to go with option 2, what do you guys think? |
I prefer option (2) from the perspective of doing what it says on the tin, but I will defer to Damien if he has a preference. |
Thank you @mauri870 for the CL, I've commented on your CL per https://go-review.googlesource.com/c/go/+/538719/comments/dfdfd7d9_f04c9321 about strictly ensuring that we only perform point 2 and that we preserve the old behavior as is, following through with https://www.hyrumslaw.com/ and only stat-ing to ensure that we have purely directories. |
@odeke-em Thanks for the feedback, I addressed your comments in the CL. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you expect to see?
a request to http://localhost:8080 returns an error response, or the content of "myFile"
What did you see instead?
server responds with 301 status code to redirect to "..//" which causes an infinite redirect loop.
The text was updated successfully, but these errors were encountered: