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
The net/http.FileServer uses net/http.ServeContent to automatically detect the content type of the 404 response body and concludes, rightly, that it is text/plain.
When the X-Content-Type-Options: nosniff is set to header, the browser will argue:
Refused to execute script from 'http://localhost:8080/xxxxxxxx.js' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled.
I think it's a bug.
REF: X-Content-Type-Options: nosniff
The text was updated successfully, but these errors were encountered:
myitcv
changed the title
[X-Content-Type-Options: nosniff] Wrong content type when 404
net/http: FileServer sets wrong content type when 404
Apr 21, 2018
@linkerlin as I mentioned over in gopherjs/gopherjs#802 (comment), I think this is more of an issue with Chrome reporting what is a derivative error, rather than net/http.(FileServer|ServeContent). Chrome has already seen that the .js file it tried to get was 404, so why it should try to do anything with the headers/body is slightly beyond me.
As a result, I'll close this for now, but please do say if you think we've reached the wrong conclusion.
What version of Go are you using (
go version
)?v1.10.1
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOBIN=""
GOCACHE="/home/linker/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/linker/go"
GORACE=""
GOROOT="/home/linker/go111"
GOTMPDIR=""
GOTOOLDIR="/home/linker/go111/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
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-build206124006=/tmp/go-build -gno-record-gcc-switches"
What did you do?
The
net/http.FileServer
usesnet/http.ServeContent
to automatically detect the content type of the 404 response body and concludes, rightly, that it is text/plain.When the
X-Content-Type-Options: nosniff
is set to header, the browser will argue:Refused to execute script from 'http://localhost:8080/xxxxxxxx.js' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled.
I think it's a bug.
REF: X-Content-Type-Options: nosniff
The text was updated successfully, but these errors were encountered: