From 9d9bf25977cfccd53202b1e0fa93e45c8fbd58e4 Mon Sep 17 00:00:00 2001 From: Chris Breiding Date: Mon, 13 Nov 2023 17:51:51 -0500 Subject: [PATCH] fix: Ensure response headers are set for extra target network requests (#28322) --- cli/CHANGELOG.md | 1 + packages/proxy/lib/http/response-middleware.ts | 4 ++++ packages/proxy/test/unit/http/response-middleware.spec.ts | 8 +++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index cd4f9293478b..672a2ab47fbe 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -5,6 +5,7 @@ _Released 11/21/2023 (PENDING)_ **Bugfixes:** +- Fixed an issue where pages opened in a new tab were missing response headers, causing them not to load properly. Fixes [#28293](https://github.com/cypress-io/cypress/issues/28293) and [#28303](https://github.com/cypress-io/cypress/issues/28303). - We now pass a flag to Chromium browsers to disable default component extensions. This is a common flag passed during browser automation. Fixed in [#28294](https://github.com/cypress-io/cypress/pull/28294). ## 13.5.0 diff --git a/packages/proxy/lib/http/response-middleware.ts b/packages/proxy/lib/http/response-middleware.ts index 903992705990..171fcc7ffa39 100644 --- a/packages/proxy/lib/http/response-middleware.ts +++ b/packages/proxy/lib/http/response-middleware.ts @@ -174,6 +174,10 @@ const FilterNonProxiedResponse: ResponseMiddleware = function () { if (this.req.isFromExtraTarget) { this.debug('response for [%s %s] is from extra target', this.req.method, this.req.proxiedUrl) + // this is normally done in the OmitProblematicHeaders middleware, but we + // don't want to omit any headers in this case + this.res.set(this.incomingRes.headers) + this.onlyRunMiddleware([ 'AttachPlainTextStreamFn', 'PatchExpressSetHeader', diff --git a/packages/proxy/test/unit/http/response-middleware.spec.ts b/packages/proxy/test/unit/http/response-middleware.spec.ts index afeb43492b58..1216a73783c7 100644 --- a/packages/proxy/test/unit/http/response-middleware.spec.ts +++ b/packages/proxy/test/unit/http/response-middleware.spec.ts @@ -103,22 +103,28 @@ describe('http/response-middleware', function () { describe('FilterNonProxiedResponse', () => { const { FilterNonProxiedResponse } = ResponseMiddleware let ctx + let headers beforeEach(() => { + headers = { 'header-name': 'header-value' } ctx = { onlyRunMiddleware: sinon.stub(), + incomingRes: { headers }, req: {}, res: { + set: sinon.stub(), off: (event, listener) => {}, }, } }) - it('runs minimal subsequent middleware if request is from an extra target', () => { + it('sets headers on response and runs minimal subsequent middleware if request is from an extra target', () => { ctx.req.isFromExtraTarget = true return testMiddleware([FilterNonProxiedResponse], ctx) .then(() => { + expect(ctx.res.set).to.be.calledWith(headers) + expect(ctx.onlyRunMiddleware).to.be.calledWith([ 'AttachPlainTextStreamFn', 'PatchExpressSetHeader',