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: Add new function TypeForPath that behaves exactly like TypeByExtension but matches on the full filename #54793

Open
nikola-jokic opened this issue Aug 31, 2022 · 4 comments · May be fixed by #53974
Labels
Milestone

Comments

@nikola-jokic
Copy link
Contributor

Related to the Issue #52609, the MIME-info database contains the regex that is not expanded by TypeByExtension.
Expanding regex is not suitable in all cases, for example 60:application/x-sharedlib:*.so.[0-9]*.

Instead, a new function can be added to the API that should receive a type based on full filename, instead of expanding every possible filename for that extension.

@gopherbot gopherbot added this to the Proposal milestone Aug 31, 2022
@seankhliao
Copy link
Member

Are those globs or regexes?
Can you include the full function signature in the issue body, as well as examples of what would match?

@neild
Copy link
Contributor

neild commented Aug 31, 2022

This arises from some discussion on https://go.dev/cl/418556.

I think the signature would be:

// TypeByPath returns the MIME type associated with a filename.
// If the name has no associated type, TypeByPath returns "".
func TypeByPath(path string) string

The motivation is that not every pattern in the MIME-info database can be expressed as an extension. In particular, these four entries are a problem:

60:application/x-sharedlib:*.so.[0-9]*
50:video/x-anim:*.anim[1-9j]
50:application/x-troff-man:*.[1-9]
50:video/mpeg:[0-9][0-9][0-9].vdr

The video/x-anim and application/x-troff-man entries could be expanded into a reasonable number of extensions (.anim1, .anim2, etc.), but video/mpeg has 1000 possible suffixes (none of which start with a .) and application/x-sharedlib isn't a suffix at all.

@nikola-jokic
Copy link
Contributor Author

Thank you for clarifying it and sorry I did not describe it well!

@nikola-jokic nikola-jokic linked a pull request Nov 9, 2022 that will close this issue
@gopherbot
Copy link

Change https://go.dev/cl/418556 mentions this issue: mime: range glob expansions in type_unix.go

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

Successfully merging a pull request may close this issue.

4 participants