You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After an hour of head scratching and cursing and found that there's a strange way how ServeFile handles any path's that end with index.html:
Instead of serving the file directly it generates a 301 redirect response to the nearest folder
Example:
http.ServeFile(w,r,"/public/blog/index.html")
this redirects to /public/blog/
This is not mentioned in the documentation and could cause undesirable behavior.
I tried to add the note about it to the documentation but got rejected because apparently Go doesn't use Github's pull request system. So I don't know how to get this into the documentation so that others won't get tripped over it.
I would actually propose that "feature" to be removed because it's based on an arbitrary of considering the trailing slash ("/") to be the equivalent of a reference to "index.html".
The text was updated successfully, but these errors were encountered:
We should just document it so we're not changing behavior. IIRC, @rsc likes (and implemented) the current behavior. I don't have much preference either way, except for I prefer things not to change. Documenting it is fine.
bradfitz
changed the title
Undocumented Behavior of ServeFile in net/http package
net/http: undocumented ServeFile index.html redirect behavior
Feb 15, 2015
That's the process. The document looks a lot more complicated than it is, because we made the instructions very thorough. Try following it through. It should take you around 10 minutes, or less.
After an hour of head scratching and cursing and found that there's a strange way how ServeFile handles any path's that end with
index.html
:Example:
http.ServeFile(w,r,"/public/blog/index.html")
this redirects to
/public/blog/
This is not mentioned in the documentation and could cause undesirable behavior.
I tried to add the note about it to the documentation but got rejected because apparently Go doesn't use Github's pull request system. So I don't know how to get this into the documentation so that others won't get tripped over it.
I would actually propose that "feature" to be removed because it's based on an arbitrary of considering the trailing slash ("/") to be the equivalent of a reference to "index.html".
The text was updated successfully, but these errors were encountered: