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

proposal: mime: expand on what is covered by builtinTypes #69530

Open
AidanWelch opened this issue Sep 19, 2024 · 4 comments
Open

proposal: mime: expand on what is covered by builtinTypes #69530

AidanWelch opened this issue Sep 19, 2024 · 4 comments
Labels
Milestone

Comments

@AidanWelch
Copy link

Proposal Details

Right now,

mime/type.go includes what seems to be a somewhat arbitrary list of built-in types:

var builtinTypesLower = map[string]string{
	".avif": "image/avif",
	".css":  "text/css; charset=utf-8",
	".gif":  "image/gif",
	".htm":  "text/html; charset=utf-8",
	".html": "text/html; charset=utf-8",
	".jpeg": "image/jpeg",
	".jpg":  "image/jpeg",
	".js":   "text/javascript; charset=utf-8",
	".json": "application/json",
	".mjs":  "text/javascript; charset=utf-8",
	".pdf":  "application/pdf",
	".png":  "image/png",
	".svg":  "image/svg+xml",
	".wasm": "application/wasm",
	".webp": "image/webp",
	".xml":  "text/xml; charset=utf-8",
}

I think some guidance on what should be included in this would be good, rather than a consumer of the package not realizing there are arbitrary gaps. In the meantime I will submit a PR that will incorporate all MDN defined "Common Types" (which also I have to admit is arbitrary, but at least covers more common usecases.)

@gopherbot gopherbot added this to the Proposal milestone Sep 19, 2024
@seankhliao
Copy link
Member

what's included is based on WHATWG mime sniffing
https://mimesniff.spec.whatwg.org/
this gives us a clear spec to adhere to, rather than an arbitrary list.

@seankhliao seankhliao changed the title proposal: mime: Expand on what is covered by builtinTypes proposal: mime: expand on what is covered by builtinTypes Sep 19, 2024
@AidanWelch
Copy link
Author

AidanWelch commented Sep 19, 2024

@seankhliao Wow, thanks for the quick response, but I'm confused as to where that actually specifies specifically just the mime types specified in builtinTypes. From my understanding that would be more relevant for net/http's DetectContentType that is actually sniffing. But, for mime's ExtensionsByType and TypeByExtension don't we have the assumption that the file extension/type is truthful and we're trying to determine the most likely type from that- whereas sniffing wouldn't even care about the given type or extension? (And so sniffing would give most(all?) plaintext types for example the same extension/type)

AidanWelch added a commit to AidanWelch/go that referenced this issue Sep 19, 2024
Simply implements the first recommended type for each file extension listed in MDN https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types

However, this excludes ".3gp" and ".3gp2" as from from I can tell it is not possible to know if it is video or audio solely from file extension.

As far as I can tell there are two previous PRs that each implemented a type simply because they were in common use.

Updates golang#69530
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/614376 mentions this issue: mime: extend "builtinTypes" to include a more complete list of common types

@gabyhelp
Copy link

Related Issues and Documentation

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants