Skip to content

net/http: ServeFile possible bug in list directory #9745

Closed
@zTrix

Description

@zTrix
$ go version
go version go1.4.1 darwin/amd64

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

$ curl localhost:8080/a
<pre>
<a href="b">b</a>
<a href="c/">c/</a>
</pre>

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions