Skip to content

Commit

Permalink
fix: don't add charset to usdz file type (#357)
Browse files Browse the repository at this point in the history
  • Loading branch information
gpoitch authored and evilebottnawi committed Feb 6, 2019
1 parent c64a2c1 commit b135b3d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
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

0 comments on commit b135b3d

Please sign in to comment.