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

Only add charset to content-type header if defined in mime db #351

Closed
wants to merge 1 commit into from

Conversation

gpoitch
Copy link
Member

@gpoitch gpoitch commented Dec 13, 2018

What kind of change does this PR introduce?
bugfix/functionality change

Did you add tests for your changes?
Yes

Summary
Closes #350
charset=utf-8 was being appended to the content-type header of every mime type regardless if it required it (#136). This PR uses mime-db to look up the charset for each mime type and add it appropriately.

Does this PR introduce a breaking change?
Don't think so unless someone was relying on the previously incorrect behavior.

Other information

  • I removed Content-Type tests from things that expect a 404. Not sure how/what was setting it.

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very good! I am afraid what it is breaking change and can break code for some people, what do you think?

@gpoitch
Copy link
Member Author

gpoitch commented Dec 13, 2018

Only thing maybe breaking is 'text/html' no longer has the charset. I assume because it could be multiple different values. It is usually set with the meta tag <meta charset="utf8">.

@gpoitch
Copy link
Member Author

gpoitch commented Dec 13, 2018

I could special case text/html to add it so this isn't potentially breaking.

@alexander-akait
Copy link
Member

@gpoitch feel free to send

@gpoitch gpoitch force-pushed the gp/mime-content-type branch from dda27f5 to 7eaeb9e Compare December 13, 2018 16:55
@codecov
Copy link

codecov bot commented Dec 13, 2018

Codecov Report

Merging #351 into master will increase coverage by 0.03%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #351      +/-   ##
==========================================
+ Coverage   96.82%   96.86%   +0.03%     
==========================================
  Files           7        7              
  Lines         252      255       +3     
==========================================
+ Hits          244      247       +3     
  Misses          8        8
Impacted Files Coverage Δ
lib/middleware.js 94.64% <100%> (+0.3%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e6cfe7c...7eaeb9e. Read the comment docs.

@codecov
Copy link

codecov bot commented Dec 13, 2018

Codecov Report

Merging #351 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #351      +/-   ##
==========================================
+ Coverage   96.77%   96.78%   +0.01%     
==========================================
  Files          12       12              
  Lines         279      280       +1     
  Branches       81       81              
==========================================
+ Hits          270      271       +1     
  Misses          9        9
Impacted Files Coverage Δ
lib/middleware.js 94.73% <100%> (+0.09%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update eb2e32b...ab3f043. Read the comment docs.

@gpoitch gpoitch force-pushed the gp/mime-content-type branch from 9f610a1 to 21a08f1 Compare December 13, 2018 17:07
lib/middleware.js Outdated Show resolved Hide resolved
@gpoitch gpoitch force-pushed the gp/mime-content-type branch from 21a08f1 to d4e4c6d Compare December 13, 2018 17:18
lib/middleware.js Outdated Show resolved Hide resolved
@alexander-akait
Copy link
Member

/cc @gpoitch can you rebase PR? I think we are ready to merge and release this

@gpoitch
Copy link
Member Author

gpoitch commented Jan 4, 2019

@evilebottnawi good to go

alexander-akait
alexander-akait previously approved these changes Jan 4, 2019
Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@alexander-akait
Copy link
Member

@gpoitch A am little afraid about breaking change, maybe we can merge this and release after holidays? For fast fixing/reverting if problem will be for many developers?

@gpoitch
Copy link
Member Author

gpoitch commented Jan 4, 2019

@evilebottnawi There is a special condition to avoid the breaking change.

As an alternative, we could maintain our own blacklist (.wasm, .usdz so far) instead of using mime-db. That would leave everything else as-is.

@alexander-akait
Copy link
Member

@gpoitch i think your solution is right, but i think we really can break some app, better release this as major, maybe we can add temporary workaround (example new option)

@gpoitch
Copy link
Member Author

gpoitch commented Jan 4, 2019

Hmm been thinking about it. I think maybe just blacklisting usdz like wasm is on master would be much less disruptive. If anymore types come up we could reconsider this.

@gpoitch
Copy link
Member Author

gpoitch commented Jan 7, 2019

@evilebottnawi Here's a simpler/safer alternative PR: #357

@gpoitch gpoitch force-pushed the gp/mime-content-type branch from 4e926c0 to ab3f043 Compare April 1, 2019 14:52
@alexander-akait
Copy link
Member

Close in favor #357

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

Successfully merging this pull request may close these issues.

Unwanted charset=UTF-8 always added to custom mime types
3 participants