discourse / mini_mime

minimal mime type library
MIT License
95 stars 34 forks source link

Extensions with multiple possible content types #25

Closed gmcgibbon closed 5 years ago

gmcgibbon commented 5 years ago

In mime-types, I can do this:

MIME::Types.type_for("a.js") # => [
  #<MIME::Type: application/ecmascript>,
  #<MIME::Type: application/javascript>,
  #<MIME::Type: text/ecmascript>,
  #<MIME::Type: text/javascript>,
  #<MIME::Type: application/x-javascript>
]

but in mini_mime, it assumes only one return. This is specifically annoying for JavaScript because I can do:

MiniMime.lookup_by_filename("a.js") # =>
#<MiniMime::Info:0x000 @extension="js", @content_type="application/ecmascript", @encoding="base64">

which tells me *.js uses base64 encoding. Have we thought of these kind of use-cases and which one is actually correct?

I should also mention there is a definition for application/javascript in the content type DB but you'll never reach it by looking up via extension.

jeremy commented 5 years ago

Have we thought of these kind of use-cases and which one is actually correct?

Yes. Lookups return the highest priority, nonobsolete, registered match.

tells me *.js uses base64 encoding

Yes. Note that "encoding" indicates the content transfer encoding used for non-8bit-clean channels, like email attachments.

paracycle commented 5 years ago

Returning application/ecmascript for the .js extension seems to be a regression on the mime-types-data repo which is where I believe mini_mime gets its database from.

You can find more details in the PR I opened regarding this: https://github.com/mime-types/mime-types-data/pull/20