-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
mime: add ".txt": "text/plain; charset=utf-8" to builtinTypesLower #46578
Comments
cc @neild |
Go 1.17 adds support on Unix-like systems for reading the FreeDesktop Shared MIME-info Database, which is a common specification supported by many Linux variants. There is a Shared MIME-Info Alpine package. While |
I was curious how other languages handle this. All languages I checked (other than Erlang and Java) take the approach suggested in this bug report. Erlang http code raises an error if it can't find a mime.types file and go takes the same approach as Java. (How often can you say that? :) ) Note the change you mention does not address this issue. There were already four such mime type files loaded in mime/type_unix.go, none of which are provided in Alpine base. This is an undocumented, run-time, external package dependency that changes how the same go code behaves. Can you think of another instance where go library behaves this way? The nuclear option is to have You could also simply update the docstrings in these two methods to document this dependency. But that "fix" depends on people reading the docs. :| I think the safest way forward is to just expand the array of default values, perhaps following Haskell's lead and autogenerating from Nginx and Apache configs. Or just copy and paste the list from them. Here are the links to how other languages handle this: The Haskell mime-types package contains a long list of default mime-types, autogenerated from "from the Apache and nginx mime.types files": https://www.stackage.org/haddock/nightly-2021-06-01/mime-types-0.1.0.9/src/Network.Mime.html#MimeMap The Rust mime crate also has a long list of defaults: https://docs.rs/mime/0.3.16/mime/ Erlang is a bit different, requiring you to drop a mime.types file in a conf directory: http://erlang.org/documentation/doc-4.8.2/lib/inets-2.3.1/doc/html/httpd_core.html#mime. It raises an error if it cannot find the mime-types files: https://github.com/erlang/otp/blob/master/lib/inets/src/http_server/httpd_conf.erl#L70-L76 Python has a long list of defaults: https://github.com/python/cpython/blob/8e2c0fd7ada79107f7e0d9c465e77fb36a9486e5/Lib/mimetypes.py#L414-L561 Ruby's mime library has a long list of defaults, but they add value by taking the simple mime file format and turning that into a set of 13 yaml files: https://github.com/mime-types/mime-types-data/tree/master/types, where each distinct mimetype is represented as eight lines of yaml. It looks like Java takes a similar approach to go; look for a set of "magic" filenames and fallback to a small set of built-in defaults: https://docs.oracle.com/javase/8/docs/api/javax/activation/MimetypesFileTypeMap.html, and
|
it's here: https://pkg.go.dev/mime#TypeByExtension
tzdata, system certificates |
Fair enough. Closing. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?What did you do?
Run the following program on Alpine Linux.
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:
http.ServeContent
to serve static files.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 andmime/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
The text was updated successfully, but these errors were encountered: