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

Don't add charset to certain file types #357

Merged
merged 2 commits into from
Feb 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ const mime = require('mime');
const DevMiddlewareError = require('./DevMiddlewareError');
const { getFilenameFromUrl, handleRangeHeaders, handleRequest, ready } = require('./util');

// Do not add a charset to the Content-Type header of these file types
// otherwise the client will fail to render them correctly.
const NonCharsetFileTypes = /\.(wasm|usdz)$/;

module.exports = function wrapper(context) {
return function middleware(req, res, next) {
// fixes #282. credit @cexoso. in certain edge situations res.locals is
Expand Down Expand Up @@ -71,8 +75,7 @@ module.exports = function wrapper(context) {

let contentType = mime.getType(filename) || '';

// do not add charset to WebAssembly files, otherwise compileStreaming will fail in the client
if (!/\.wasm$/.test(filename)) {
if (!NonCharsetFileTypes.test(filename)) {
contentType += '; charset=UTF-8';
}

Expand Down
15 changes: 13 additions & 2 deletions test/tests/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,17 +312,21 @@ describe('Server', () => {
});
});

describe('WebAssembly', () => {
describe('Special file type headers', () => {
before((done) => {
app = express();
const compiler = webpack(webpackConfig);
instance = middleware(compiler, {
stats: 'errors-only',
logLevel
logLevel,
mimeTypes: {
'model/vnd.pixar.usd': ['usdz']
}
});
app.use(instance);
listen = listenShorthand(done);
instance.fileSystem.writeFileSync('/hello.wasm', 'welcome');
instance.fileSystem.writeFileSync('/3dAr.usdz', '010101');
});
after(close);

Expand All @@ -332,6 +336,13 @@ describe('Server', () => {
.expect('welcome')
.expect(200, done);
});

it('request to 3dAr.usdz', (done) => {
request(app).get('/3dAr.usdz')
.expect('Content-Type', 'model/vnd.pixar.usd')
.expect('010101')
.expect(200, done);
});
});

describe('MultiCompiler', () => {
Expand Down