fix: handle compression for custom-server render calls (#16378) (#18891)

Co-authored-by: Radosław Grochowski <radoslaw.grochowski@grupawp.pl>
Co-authored-by: Tim Neutkens <timneutkens@me.com>
This commit is contained in:
Radosław Grochowski 2021-05-07 19:37:51 +02:00 committed by GitHub
parent 9d25194e7d
commit 7f1c8a9bbe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View file

@ -1315,6 +1315,11 @@ export default class Server {
return this.handleRequest(req, res, parsedUrl)
}
// Custom server users can run `app.render()` which needs compression.
if (this.renderOpts.customServer) {
this.handleCompression(req, res)
}
if (isBlockedPage(pathname)) {
return this.render404(req, res, parsedUrl)
}

View file

@ -183,4 +183,17 @@ describe('Custom Server', () => {
expect(stderr).toContain('Cannot render page with path "dashboard"')
})
})
describe('compression handling', function () {
beforeAll(() => startServer())
afterAll(() => killApp(server))
it.each(['/', '/no-query'])(
'should handle compression for route %s',
async (route) => {
const response = await fetchViaHTTP(appPort, route)
expect(response.headers.get('Content-Encoding')).toBe('gzip')
}
)
})
})