Skip to content

Commit b2a6fed

Browse files
dmohnsevilebottnawi
authored andcommitted
fix: do not overwrite Content-Type if header already exists (#377)
1 parent e5bd8f8 commit b2a6fed

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/middleware.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ module.exports = function wrapper(context) {
7979
contentType += '; charset=UTF-8';
8080
}
8181

82-
res.setHeader('Content-Type', contentType);
82+
if (!res.getHeader('Content-Type')) {
83+
res.setHeader('Content-Type', contentType);
84+
}
8385
res.setHeader('Content-Length', content.length);
8486

8587
const { headers } = context.options;

test/tests/server.js

+21
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,27 @@ describe('Server', () => {
259259
});
260260
});
261261

262+
describe('custom Content-Type', () => {
263+
before((done) => {
264+
app = express();
265+
const compiler = webpack(webpackConfig);
266+
instance = middleware(compiler, {
267+
stats: 'errors-only',
268+
logLevel,
269+
headers: { 'Content-Type': 'application/octet-stream' }
270+
});
271+
app.use(instance);
272+
listen = listenShorthand(done);
273+
});
274+
after(close);
275+
276+
it('Do not guess mime type if Content-Type header is found ', (done) => {
277+
request(app).get('/bundle.js')
278+
.expect('Content-Type', 'application/octet-stream')
279+
.expect(200, done);
280+
});
281+
});
282+
262283
describe('custom mimeTypes', () => {
263284
before((done) => {
264285
app = express();

0 commit comments

Comments
 (0)