Skip to content

Commit

Permalink
fix: Ensure original headers are included with extra target requests (#…
Browse files Browse the repository at this point in the history
…28671)

* fix: extra target request headers are overwritten

Include original headers with the special "X-Cypress-Is-From-Extra-Target" that is added so fetch requests can include custom headers.

* Add details to changelog

* refactor

---------

Co-authored-by: Chris Breiding <[email protected]>
Co-authored-by: Chris Breiding <[email protected]>
  • Loading branch information
3 people authored Jan 11, 2024
1 parent 09ce5c1 commit 46c2080
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ _Released 1/16/2024 (PENDING)_
- Fixed an issue where some cross-origin logs, like assertions or cy.clock(), were getting too many dom snapshots. Fixes [#28609](https://github.com/cypress-io/cypress/issues/28609).
- Fixed asset capture for Test Replay for requests that are routed through service workers. This addresses an issue where styles were not being applied properly in Test Replay and `cy.intercept` was not working properly for requests in this scenario. Fixes [#28516](https://github.com/cypress-io/cypress/issues/28516).
- Fixed an issue where visiting an `http://` site would result in an infinite reload/redirect loop in Chrome 114+. Fixes [#25891](https://github.com/cypress-io/cypress/issues/25891).
- Fixed an issue where requests made from extra tabs do not include their original headers. Fixes [#28641](https://github.com/cypress-io/cypress/issues/28641).

**Performance:**

Expand Down
9 changes: 8 additions & 1 deletion packages/server/lib/browsers/browser-cri-client.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _ from 'lodash'
import Bluebird from 'bluebird'
import CRI from 'chrome-remote-interface'
import Debug from 'debug'
Expand Down Expand Up @@ -376,9 +377,15 @@ export class BrowserCriClient {
// we mark extra targets with this header, so that the proxy can recognize
// where they came from and run only the minimal middleware necessary
extraTargetCriClient.on('Fetch.requestPaused', async (params: Protocol.Fetch.RequestPausedEvent) => {
// headers are received as an object but need to be an array to modify them
const headers = _.map(params.request.headers, (value, name) => ({ name, value }))

const details: Protocol.Fetch.ContinueRequestRequest = {
requestId: params.requestId,
headers: [{ name: 'X-Cypress-Is-From-Extra-Target', value: 'true' }],
headers: [
...headers,
{ name: 'X-Cypress-Is-From-Extra-Target', value: 'true' },
],
}

extraTargetCriClient.send('Fetch.continueRequest', details).catch((err) => {
Expand Down
10 changes: 8 additions & 2 deletions packages/server/test/unit/browsers/browser-cri-client_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,17 @@ describe('lib/browsers/cri-client', function () {
criClient.send.withArgs('Fetch.continueRequest').resolves()

await BrowserCriClient._onAttachToTarget(options as any)
await criClient.on.lastCall.args[1]({ requestId: 'request-id' })
await criClient.on.lastCall.args[1]({
requestId: 'request-id',
request: { headers: { 'X-Another-Custom-Header': 'value' } },
})

expect(criClient.send).to.be.calledWith('Fetch.continueRequest', {
requestId: 'request-id',
headers: [{ name: 'X-Cypress-Is-From-Extra-Target', value: 'true' }],
headers: [
{ name: 'X-Another-Custom-Header', value: 'value' },
{ name: 'X-Cypress-Is-From-Extra-Target', value: 'true' },
],
})
})

Expand Down

5 comments on commit 46c2080

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 46c2080 Jan 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.6.3/linux-arm64/develop-46c2080ffdfe526c36c04f54e737084768cdf6c3/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 46c2080 Jan 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.6.3/linux-x64/develop-46c2080ffdfe526c36c04f54e737084768cdf6c3/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 46c2080 Jan 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.6.3/darwin-x64/develop-46c2080ffdfe526c36c04f54e737084768cdf6c3/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 46c2080 Jan 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.6.3/darwin-arm64/develop-46c2080ffdfe526c36c04f54e737084768cdf6c3/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 46c2080 Jan 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.6.3/win32-x64/develop-46c2080ffdfe526c36c04f54e737084768cdf6c3/cypress.tgz

Please sign in to comment.