-
Notifications
You must be signed in to change notification settings - Fork 133
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
support filepaths to .contentType() #15
Conversation
So, unlike a Simply do this in your code, though: mime.contentType(path.basename('path/to/file.json')) |
Sure, I just thought it'd be a nice API to save the steps. Regarding breaking mime types, judging from the tests, this change was backwards compatible in that regard. As far as I can tell, the line that checks for the presence of the assert.equal(contentType('text/html; charset=ascii'), 'text/html; charset=ascii') If I'm not overlooking anything, I think it makes for a more useful API to cater to:
Since in the first case, I don't need the method to generate a content-type header value, while in the second, I do. Is there a way we haven't thought of yet that could support both use cases? Thanks for the consideration! |
Ah. Can you tell me what will happen to the people currently doing |
They'd be busted by the new check for I pushed a new commit that would end support for .contentType() accepting content-types. As explained above, I'd rather use this method to get a content type back from a file path or file type. However, if there is a safe solution to detect when a content type is provided, it would be even better to continue to support all use cases. |
Cool. So that would bump this PR to a new major. It's certainly doable, but there wouldn't be a timeline on that, unfortunately. In reality, our intention was actually to remove |
yeah i ran into this issue sometimes. sometimes i pass a filename, other times i pass a mime type, but i expect both to work. |
@dougwilson we could also use the |
Hm, yea, maybe, though I wasn't intending to have a dep on |
As long as |
I still need to revive the |
The only reason I thought this was supported in the first place was the second example in the readme (https://github.com/jshttp/mime-types/blob/master/README.md#mimecontenttypetype): mime.contentType('file.json') // 'application/json; charset=utf-8' When I saw that, I thought "that makes so much sense!" That's my most common use case. I don't know why getting back what you give it is a more common one, but regardless, I'll continue to be a happy user of the library. Thanks! |
Right. This is one reason I don't particularly like functions that behave differently depending on their argument. Ideally we would have a CT function that takes a type and a different CT function that takes file paths. |
I noticed the readme makes it seem as though file paths will please the .contentType() method, but when used with a path like "here/is/my/file.json", the directory separator
/
is being mistaken for a content-type's/
, which is interpreted as "I don't need you to lookup the content-type". Instead of looking for a/
, I changed it look for a;
. Hope this isn't a terrible solution!