From e6fe0cdc07c6b8a8ffee3469c292d8b58380d848 Mon Sep 17 00:00:00 2001 From: Zach Bloomquist Date: Thu, 22 Oct 2020 13:17:58 -0400 Subject: [PATCH] fix: fix loading redirects with TE: chunked (#8896) --- .../cypress/integration/commands/net_stubbing_spec.ts | 11 +++++++++++ packages/driver/cypress/plugins/server.js | 9 ++++++++- packages/proxy/lib/http/response-middleware.ts | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/driver/cypress/integration/commands/net_stubbing_spec.ts b/packages/driver/cypress/integration/commands/net_stubbing_spec.ts index 5884d60bca..5da8c10128 100644 --- a/packages/driver/cypress/integration/commands/net_stubbing_spec.ts +++ b/packages/driver/cypress/integration/commands/net_stubbing_spec.ts @@ -411,6 +411,17 @@ describe('network stubbing', function () { }) context('network handling', function () { + // @see https://github.com/cypress-io/cypress/issues/8497 + it('can load transfer-encoding: chunked redirects', function () { + const url4 = 'http://localhost:3501/fixtures/generic.html' + const url3 = `http://localhost:3501/redirect?href=${encodeURIComponent(url4)}` + const url2 = `https://localhost:3502/redirect?chunked=1&href=${encodeURIComponent(url3)}` + const url1 = `https://localhost:3502/redirect?chunked=1&href=${encodeURIComponent(url2)}` + + cy.visit(url1) + .location('href').should('eq', url4) + }) + context('can intercept against any domain', function () { beforeEach(function () { // reset origin diff --git a/packages/driver/cypress/plugins/server.js b/packages/driver/cypress/plugins/server.js index 3a12b373bb..0bef83dc2e 100644 --- a/packages/driver/cypress/plugins/server.js +++ b/packages/driver/cypress/plugins/server.js @@ -42,7 +42,14 @@ const createApp = (port) => { }) app.get('/redirect', (req, res) => { - res.redirect(301, req.query.href) + if (req.query.chunked) { + res.setHeader('transfer-encoding', 'chunked') + res.removeHeader('content-length') + } + + res.statusCode = 301 + res.setHeader('Location', req.query.href) + res.end() }) // allows us to serve the testrunner into an iframe for testing diff --git a/packages/proxy/lib/http/response-middleware.ts b/packages/proxy/lib/http/response-middleware.ts index e691600697..17c499f340 100644 --- a/packages/proxy/lib/http/response-middleware.ts +++ b/packages/proxy/lib/http/response-middleware.ts @@ -299,6 +299,7 @@ const OmitProblematicHeaders: ResponseMiddleware = function () { 'set-cookie', 'x-frame-options', 'content-length', + 'transfer-encoding', 'content-security-policy', 'content-security-policy-report-only', 'connection',