Skip to content

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

Closed
@Russtopia

Description

@Russtopia

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRequestIssues asking for a new feature that does not need a proposal.FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Proposal

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions