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

fix: force gzip when no accept encoding header is sent and use identity if gzip is not sent #28026

Merged
merged 14 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
6 changes: 4 additions & 2 deletions packages/proxy/lib/http/request-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ const EndRequestsToBlockedHosts: RequestMiddleware = function () {
const StripUnsupportedAcceptEncoding: RequestMiddleware = function () {
const span = telemetry.startSpan({ name: 'strip:unsupported:accept:encoding', parentSpan: this.reqMiddlewareSpan, isVerbose })

// Cypress can only support plaintext or gzip, so make sure we don't request anything else
// Cypress can only support plaintext or gzip, so make sure we don't request anything else, by either filtering down to `gzip` or explicitly specifying `identity`
const acceptEncoding = this.req.headers['accept-encoding']

span?.setAttributes({
Expand All @@ -365,8 +365,10 @@ const StripUnsupportedAcceptEncoding: RequestMiddleware = function () {
if (doesAcceptHeadingIncludeGzip) {
this.req.headers['accept-encoding'] = 'gzip'
} else {
delete this.req.headers['accept-encoding']
this.req.headers['accept-encoding'] = 'identity'
}
} else {
this.req.headers['accept-encoding'] = 'identity'
ryanthemanuel marked this conversation as resolved.
Show resolved Hide resolved
ryanthemanuel marked this conversation as resolved.
Show resolved Hide resolved
}

span?.end()
Expand Down
23 changes: 19 additions & 4 deletions packages/server/test/integration/http_requests_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1138,11 +1138,10 @@ describe('Routes', () => {
})
})

it('removes accept-encoding when nothing is supported', function () {
nock(this.server.remoteStates.current().origin, {
badheaders: ['accept-encoding'],
})
it('sets accept-encoding header to "identity" when nothing is supported', function () {
nock(this.server.remoteStates.current().origin)
.get('/accept')
.matchHeader('accept-encoding', 'identity')
.reply(200, '<html>accept</html>')

return this.rp({
Expand All @@ -1158,6 +1157,22 @@ describe('Routes', () => {
expect(res.body).to.eq('<html>accept</html>')
})
})

it('sets accept-encoding header to "identity" when no header is passed', function () {
ryanthemanuel marked this conversation as resolved.
Show resolved Hide resolved
nock(this.server.remoteStates.current().origin)
.get('/accept')
.matchHeader('accept-encoding', 'identity')
ryanthemanuel marked this conversation as resolved.
Show resolved Hide resolved
.reply(200, '<html>accept</html>')

return this.rp({
url: 'http://www.github.com/accept',
})
.then((res) => {
expect(res.statusCode).to.eq(200)

expect(res.body).to.eq('<html>accept</html>')
})
})
})

context('304 Not Modified', () => {
Expand Down
Loading