Skip to content
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

net/http: FileServer() directory listings cannot be styled #29945

Closed
Russtopia opened this issue Jan 26, 2019 · 3 comments

Comments

Projects
None yet
4 participants
@Russtopia
Copy link

commented Jan 26, 2019

What version of Go are you using (go version)?

$ go version
go version go1.11.3 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/russtopia/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/russtopia/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib64/go1.11.3"
GOTMPDIR=""
GOTOOLDIR="/usr/lib64/go1.11.3/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build777521497=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Developing an app using http.FileServer(), it became apparent by examining the net/http/fs.go dirList() function, which is used by serveFile() to emit HTML listings of directories, that the format/styling of these directory pages is hardcoded, with no facility for callers to apply basic header, footer or link styling to allow consistency with the rest of custom endpoints an application might serve, by http.HandleFunc() etc.

Basic styling allowing applications to override the basic HTTP headers, HTML header, body and footer portions of a served directory listing page would fill a significant gap in the customization facilities of the core http package, such that applications serving custom endpoints as well as bare filesystem trees could have a consistent presentation (eg. vendor backgrounds, alink styling, legal disclaimers when browsing directories, and so on).

What did you expect to see?

Some facility for applications to apply basic styling to directory pages served by http.FileServer().

What did you see instead?

Hardcoded <pre>...</pre> blocks emitted by dirList(), for directory listings, and no control over HTTP headers or alink styles.

Russtopia added a commit to Russtopia/go that referenced this issue Jan 26, 2019

@agnivade agnivade added this to the Unplanned milestone Jan 26, 2019

@gopherbot

This comment has been minimized.

Copy link

commented Jan 26, 2019

Change https://golang.org/cl/159757 mentions this issue: net/http: adds hooks to style dir listings served from http.FileServer() Fixes #29945

@bradfitz

This comment has been minimized.

Copy link
Member

commented Jan 26, 2019

Sorry, but this has already been declined in the past.

If you want a fancy fileserver, feel free to fork net/http's and put it on GitHub and reference it here for others to find.

@Russtopia

This comment has been minimized.

Copy link
Author

commented Jan 26, 2019

OK, makes sense. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.