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

Content-Type set by other middleware gets overwritten #376

Closed
1 of 2 tasks
dmohns opened this issue Mar 6, 2019 · 3 comments
Closed
1 of 2 tasks

Content-Type set by other middleware gets overwritten #376

dmohns opened this issue Mar 6, 2019 · 3 comments

Comments

@dmohns
Copy link
Contributor

dmohns commented Mar 6, 2019

  • Operating System: macOS 10.14.3
  • Node Version: v11.10.0
  • NPM Version: 6.8.0
  • webpack version: 4.29.6
  • webpack-dev-middleware Version: 3.6.0
  • This is a feature request
  • This is a bug

Code

I am working with a custom middleware to serve static assets from their gzipped versions, like so:

app.use(function (req, res, next) {
  if (req.url.endsWith('css')) {
    req.url = req.url + '.gz';
    res.set('Content-Encoding', 'gzip');
    res.set('Content-Type', 'text/css');
  }
  next()
});

Unfortunately, webpack-dev-middleware overwrites Content-Type regardless of whether or not it's been set already by another middleware. See

res.setHeader('Content-Type', contentType);

Expected Behavior

In the resulting request: Content-Type: text/css

Actual Behavior

In the resulting request: Content-Type: application/gzip; charset=UTF-8

For Bugs; How can we reproduce the behavior?

For Features; What is the motivation and/or use-case for the feature?

@dmohns dmohns changed the title Do not overwrite Content-Type when already present Content-Type set by other middleware gets overwritten Mar 6, 2019
@dmohns
Copy link
Contributor Author

dmohns commented Mar 6, 2019

@clshortfuse you had some trouble with incorrect mimeTypes set by webpack-dev-middleware. Is this problem similar?

@alexander-akait
Copy link
Member

We should add check if header already exists, feel free to send a PR with fix 👍

dmohns added a commit to dmohns/webpack-dev-middleware that referenced this issue Mar 6, 2019
When the Content-Type header is already present (for example it has been 
set by other middleware) we do not overwrite it.

Closes webpack#376
@alexander-akait
Copy link
Member

Release https://github.com/webpack/webpack-dev-middleware/releases/tag/v3.6.1

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

No branches or pull requests

2 participants