Skip to content

Unwanted charset=UTF-8 always added to custom mime types #350

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

Closed
2 tasks done
gpoitch opened this issue Dec 12, 2018 · 10 comments
Closed
2 tasks done

Unwanted charset=UTF-8 always added to custom mime types #350

gpoitch opened this issue Dec 12, 2018 · 10 comments

Comments

@gpoitch
Copy link
Member

gpoitch commented Dec 12, 2018

  • Operating System: macOS 10.14
  • Node Version: 10.4.1
  • NPM Version: 6.4.1
  • webpack version: 4.27.1
  • webpack-dev-middleware Version: 3.4.0
  • This is a feature request
  • This is a bug

Since #136, charset=UTF-8 is always appended to the Content-Type header. If I define custom mime types, I believe that this shouldn't be appended.

For example, mobile safari can render 3d/AR models in a native viewer when a file is served with model/vnd.pixar.usd. When setting the option mimeTypes: { 'model/vnd.pixar.usd', ['usdz'] }, the server will return: Content-Type: model/vnd.pixar.usd; charset=UTF-8. The addition of the charset causes the browser to incorrectly interpret the mime type.

This is already special-cased for wasm.

Expected Behavior

charset=UTF-8 is not appended to every Content-Type header when defining custom mimeTypes.

Actual Behavior

charset=UTF-8 is always appended

I can make a PR if you agree on the proposed behavior.

@alexander-akait
Copy link
Member

@gpoitch hm, sound reasonable, any ideas how we can detect when we need add charset when not?

@gpoitch
Copy link
Member Author

gpoitch commented Dec 12, 2018

@evilebottnawi yes, after some digging looks like it should be added only if charset is defined for the type in mime-db (https://github.com/jshttp/mime-db/blob/master/db.json). We could conditionally add charset based on that instead.

@alexander-akait
Copy link
Member

@gpoitch 👍 PR welcome and when we release new version

@gpoitch
Copy link
Member Author

gpoitch commented Dec 13, 2018

#351

@alexander-akait
Copy link
Member

/cc @hiroppy I think we should not change logic, same logic using in many places in express and express middleware https://github.com/expressjs/serve-index/blob/master/index.js#L543, i think will be great implement an option for this

@hiroppy
Copy link
Member

hiroppy commented Oct 28, 2019

hmm, it seems we need to overwrite below lines.

  res.setHeader('Content-Type', type + '; charset=utf-8')
  res.setHeader('Content-Length', Buffer.byteLength(body, 'utf8'))

  // body
  res.end(body, 'utf8')

Yes, I agree with you. We need to provide a new option for overwriting this.

@hiroppy
Copy link
Member

hiroppy commented Oct 28, 2019

ok, I'll take over this.

@hiroppy hiroppy self-assigned this Oct 28, 2019
@alexander-akait
Copy link
Member

Just for information, https://github.com/expressjs/serve-static/blob/master/index.js do not use utf8, maybe we should investigate deeply

@hiroppy
Copy link
Member

hiroppy commented Oct 28, 2019

This problem seems to be difficult because express is writing utf-8 directly.😥

@alexander-akait
Copy link
Member

Fixed in next

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment