-
-
Notifications
You must be signed in to change notification settings - Fork 376
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
bug: unknown mime type sets Content-Type as 'null; charset=UTF-8' #354
Comments
@alexander-akait This bug is back, but slightly different. Unknown mime types are now forced to Now Chrome states: I'm testing with the 4.0.0-beta of |
Seems like this new behavior started with b83a1db#diff-9a117d52a8a2cb3e5f498575bdfdea4dc32418180c09029454fbaf7f95ebe5a1R76 I'm not seeing any reason specifically why this new behavior was introduced though, or a way to work around it. |
Because Node.js do the same? |
What is the problem, just use |
I don't know what you mean. NodeJS doesn't set https://github.com/nodejs/node/blob/master/lib/_http_outgoing.js As explained in the issue from Jan 2019, an explicit
Having to rewrite all applications to new URLs simply for
Again, I don't understand the reasoning behind incorporating a breaking change to forcing all unknown mime types to
|
PR welcome |
Should be easy to fix |
So, I wrote the code fix and I'll send in the PR tomorrow. But there's an issue with how to test it... Background: With, Express if you don't set a Express has a pretty long dependency tree, so trying to test what happens after the current middleware executes is a rather difficult task. In this case, it's
Observations: There's really a more complex question with how exactly this library wants to support other web frameworks. Each has their own quirks and ways of doing things:
Solution: Honestly, the best solution I can come up with is just acknowledge this Recommendation: In the future, there should probably be an abstract class that |
Yes, I noticed that different frameworks is doing about different things, I think in this case, we just need to leave the commentary in the code and in the documentation |
Fixes webpack#354 * Only set 'Content-Type' header if mime type is known. * Remove testing for 'Content-Type' of unknown types. * Do not test against `application/octet-stream'. Unknown media types should have content-type blank. Because frameworks handle Content-Types differently, it is not possible to standardize testing at the moment. Tests against `application/octet-stream` can create false positives with Express because of this. https://tools.ietf.org/html/rfc7231#section-3.1.1.5 broofa/mime#139
Code
Expected Behavior
Unknown mime-types should return a blank media-type in Content-Type
Actual Behavior
media-type
is being listed as nullFor Bugs; How can we reproduce the behavior?
Create a webpack package that outputs any file without an extension.
The issue is in
middleware.js
webpack-dev-middleware/lib/middleware.js
Line 72 in e6cfe7c
mime.getType(filename);
will return null if it cannot lookup the media-type.https://github.com/broofa/node-mime/blob/a1d884c1672f34031af15718b25b93dee00dc3ad/Mime.js#L82
When
'; charset=UTF-8'
is added to null, the result isContent-Type: null; charset=UTF-8
.webpack-dev-middleware/lib/middleware.js
Line 76 in e6cfe7c
Different browsers treat
null
differently. Chrome, Safari, and Firefox will try to interpret the file (which in my use case istext/html
). IE and Edge will not and treat it asapplication/octet-stream
which will cause a download prompt to appear. Using*/*
will produce the same result.If we don't use 'null', and instead, leave the media-type blank, all the above browsers will try to interpret the file when
Content-Type: ; charset=UTF-8
is used. Since I'm using it for HTML file, it gets interpreted correct by IE and Edge. That's the expected behavior according to RFC 7231:https://tools.ietf.org/html/rfc7231#section-3.1.1.5
The text was updated successfully, but these errors were encountered: