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: add built-in mime type for *.mjs #30547

Closed
dkumor opened this issue Mar 3, 2019 · 8 comments
Closed

net/http: add built-in mime type for *.mjs #30547

dkumor opened this issue Mar 3, 2019 · 8 comments
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@dkumor
Copy link

dkumor commented Mar 3, 2019

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

$ go version
go version go1.12 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/daniel/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/daniel/.go"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/go"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/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-build067538039=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Given a folder with the following files:

index.html:

<html>
<body>
<script type="module" src="test.mjs"></script>
</body>
</html>

and test.mjs (see: https://developers.google.com/web/fundamentals/primers/modules)

console.log("hi!");

My code serves the above with http.FileServer, and I navigate to / in my browser, opening index.html

What did you expect to see?

I expected hi to be printed in the javascript console

What did you see instead?

The following error in chrome:

Failed to load module script: The server responded with a non-JavaScript MIME type of "text/plain". Strict MIME type checking is enforced for module scripts per HTML spec.

This is because .mjs is not a recognized mimetype. This can easily be worked around by manually adding .mjs to the mime database:

mime.AddExtensionType(".mjs", "application/javascript")

Or, technically, one can just use .js - but .mjs seems to be commonly used.

However, since es modules are a standard, and will become more common in the future, it would be nice to have the mimetype built in.

@bradfitz bradfitz changed the title es modules mjs extension in http.FileServer net/http: add built-in mime type for *.mjs Mar 5, 2019
@bradfitz bradfitz added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Mar 5, 2019
@bradfitz
Copy link
Contributor

bradfitz commented Mar 5, 2019

Is there an official spec that's proposing standardizing that mime type for that extension? (something more formal that the page you linked)

@dkumor
Copy link
Author

dkumor commented Mar 5, 2019

That's a good question.

Mime

mjs Extension

I did not find anything "official", other than common usage:

@andybons
Copy link
Member

andybons commented May 6, 2019

With #31327 landed perhaps this should go in, too.

@bradfitz
Copy link
Contributor

bradfitz commented May 6, 2019

Sure. Send a change. Makes sense to also do it in Go 1.13 to match #31327.

@bradfitz bradfitz added this to the Go1.13 milestone May 6, 2019
@bradfitz bradfitz added help wanted NeedsFix The path to resolution is known, but the work has not been done. labels May 6, 2019
@gopherbot gopherbot removed the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label May 6, 2019
@andybons
Copy link
Member

andybons commented May 6, 2019

Looks like it was already done in https://golang.org/cl/169502

Closing :)

@andybons andybons closed this as completed May 6, 2019
@dkumor
Copy link
Author

dkumor commented May 6, 2019

It looks like the mime type added was text/javascript in mime/type.go line 72, which was obsoleted, and replaced with application/javascript in RFC 4329.

It is my understanding the mimetype should therefore be application/javascript.
This is corroborated by the IANA website, which uses application/javascript as the only mimetype for javascript (https://www.iana.org/assignments/media-types/media-types.xhtml).

Nevertheless, it is great to hear that the mimetype was added!

@bradfitz
Copy link
Contributor

bradfitz commented May 6, 2019

@dkumor, I sent a fix. Thanks.

@gopherbot
Copy link

Change https://golang.org/cl/175459 mentions this issue: mime: update .mjs MIME type to application/json instead of text/json

gopherbot pushed a commit that referenced this issue May 13, 2019
.mjs should be the same MIME type as .js, and RFC 4329 says that
text/javascript is obsolete, even back in 2006:

    https://tools.ietf.org/html/rfc4329#section-7.1

I didn't notice this when I recently reviewed CL 169502.

Also, re-sort it.

Updates #30547

Change-Id: I8ed8ddaf06c8a08b010423ebd071f39ef3a325e5
Reviewed-on: https://go-review.googlesource.com/c/go/+/175459
Reviewed-by: Andrew Bonventre <andybons@golang.org>
Run-TryBot: Andrew Bonventre <andybons@golang.org>
@golang golang locked and limited conversation to collaborators May 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants