Skip to content

Commit

Permalink
Bug/issue 1159 devServer proxy routing broken with content encoding h…
Browse files Browse the repository at this point in the history
…eader (#1160)

* filter out content encoding header from proxy request resource

* comment callout regarding devServer usage in non development scenarios

* add test case
  • Loading branch information
thescientist13 committed Nov 9, 2023
1 parent 5e1cb2a commit 3c9b8ca
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/cli/src/lifecycles/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ async function getStaticServer(compilation, composable) {
await next();
});

// TODO devServer.proxy is not really just for dev
// should it be renamed? should this be a middleware?
app.use(async (ctx, next) => {
try {
const url = new URL(`http://localhost:${port}${ctx.url}`);
Expand Down
12 changes: 11 additions & 1 deletion packages/cli/src/plugins/resource/plugin-dev-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,18 @@ class DevProxyResource extends ResourceInterface {
method: request.method,
headers: request.header
});
const response = await fetch(requestProxied);
const filteredResponseHeaders = new Headers();

return await fetch(requestProxied);
// filter out content-encoding to make sure browsers do not try and decode responses
// https://github.com/ProjectEvergreen/greenwood/issues/1159
response.headers.forEach((value, key) => {
if (key !== 'content-encoding') {
filteredResponseHeaders.set(key, value);
}
});

return new Response(response.body, { headers: filteredResponseHeaders });
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,12 @@ describe('Develop Greenwood With: ', function() {
done();
});

// https://github.com/ProjectEvergreen/greenwood/issues/1159
it('should not return a content-encoding header', function(done) {
expect(response.headers['content-encoding']).to.equal(undefined);
done();
});

it('should return the correct response body', function(done) {
expect(response.body).to.have.lengthOf(1);
done();
Expand Down

0 comments on commit 3c9b8ca

Please sign in to comment.