Skip to content

net/http: undocumented ServeFile index.html redirect behavior #9876

@laszlothewiz

Description

@laszlothewiz

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".

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions