-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Description
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version)?
$ go version
go version go1.15.10 linux/386
What did you do?
Run the following program on Alpine Linux.
package main
import "path/filepath"
import "fmt"
import "mime"
func main() {
name := "x.txt"
ext := filepath.Ext(name);
fmt.Printf("mime type for extension '%s' = %v\n", ext, mime.TypeByExtension(ext))
}
What did you expect to see?
mime type for extension '.txt' = text/plain; charset=utf-8
What did you see instead?
mime type for extension '.txt' =
I suggest adding a txt to the list of built-in mime types.
Before I built the small program above to isolate the problem, the behavior I saw was:
- Built a go web server that used
http.ServeContentto serve static files. - On my development box (OSX), the mime type was set correctly and the browser rendered the content as plain text
- On the production box, the mime type was blank and the browser rendered text as HTML.
At first, I first assumed the Nginx proxy was behaving badly. Eventually, I figured out that Alpine base does not provide any of the four mime files that mime/type_unix.go looks for and mime/type.go does not provide a built-in default for the .txt extension.
I opened a bug with Alpine, but they did not think this corner case was worth adding /etc/mime.types to the Apline base. I can see their point, as this is a corner case and the mime-type file used depends on the application more than the host; mail, Apache, and Nginx all have different ideas about where the mime-type file lives---the latter two even disagree on the file format. There does not seem to be a standard location.
Does this issue reproduce with the latest release (go1.16.5)?
Based on my read of these two sources, yes.
System details
GO111MODULE=""
GOARCH="386"
GOBIN=""
GOCACHE="/home/mark/.cache/go-build"
GOENV="/home/mark/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="386"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/mark/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/mark/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_386"
GCCGO="gccgo"
GO386="387"
AR="ar"
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 -m32 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build108867270=/tmp/go-build -gno-record-gcc-switches"
GOROOT/bin/go version: go version go1.15.10 linux/386
GOROOT/bin/go tool compile -V: compile version go1.15.10
uname -sr: Linux 4.4.68-0-grsec