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
I don't know if this is a bug, or designed to be like this.
I implemented a http server using official http package.
I served a static directory using http.ServeFile(w, r, fp), if fp is a directory, the go server returns a very simple directory listing html page, which is good.
The problem is that the relative path is wrong when the url does not ends with slash(/).
For example, in webroot/a dir, we have file named b and directory named c
If you look at the source, comparing ServeFile with FileServer, you
will see that the redirection is intentionally disabled.
I think it's because ServeFile is a lower-level routine and if you want
to use the directory listing feature, you should handle the redirection
in your code. And if you just want to serve some files from the file
system, FileServer is a better choice.
Also, the docs says that ServeFile serves the content of the file or
directory, but that doesn't include any redirection, so the docs and
code agrees. Closing as working as intended.
I don't know if this is a bug, or designed to be like this.
I implemented a http server using official http package.
I served a static directory using
http.ServeFile(w, r, fp)
, if fp is a directory, the go server returns a very simple directory listing html page, which is good.The problem is that the relative path is wrong when the url does not ends with slash(/).
For example, in
webroot/a
dir, we have file namedb
and directory namedc
So that if you click b, it will point to "localhost:8080/b", not "localhost:8080/a/b"
But if I get
localhost:8080/a/
, then everything works.I checked the code, and it's caused by http://golang.org/src/net/http/fs.go dirList func, line 86.
I just wonder, is it designed to be so or a bug? Does a 302 redirection to
http://domain/dir/
make more sense?The text was updated successfully, but these errors were encountered: