Skip to content

Commit 7f1c8a9

Browse files
radoslawgrochowskiRadosław Grochowskitimneutkens
authored
fix: handle compression for custom-server render calls (vercel#16378) (vercel#18891)
Co-authored-by: Radosław Grochowski <[email protected]> Co-authored-by: Tim Neutkens <[email protected]>
1 parent 9d25194 commit 7f1c8a9

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

packages/next/next-server/server/next-server.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,11 @@ export default class Server {
13151315
return this.handleRequest(req, res, parsedUrl)
13161316
}
13171317

1318+
// Custom server users can run `app.render()` which needs compression.
1319+
if (this.renderOpts.customServer) {
1320+
this.handleCompression(req, res)
1321+
}
1322+
13181323
if (isBlockedPage(pathname)) {
13191324
return this.render404(req, res, parsedUrl)
13201325
}

test/integration/custom-server/test/index.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,17 @@ describe('Custom Server', () => {
183183
expect(stderr).toContain('Cannot render page with path "dashboard"')
184184
})
185185
})
186+
187+
describe('compression handling', function () {
188+
beforeAll(() => startServer())
189+
afterAll(() => killApp(server))
190+
191+
it.each(['/', '/no-query'])(
192+
'should handle compression for route %s',
193+
async (route) => {
194+
const response = await fetchViaHTTP(appPort, route)
195+
expect(response.headers.get('Content-Encoding')).toBe('gzip')
196+
}
197+
)
198+
})
186199
})

0 commit comments

Comments
 (0)