fix: #29171 set correct host header with fetch #29452
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Additional details
Use of node-fetch, in particular during launch of the Cypress UI when started with
cypress open
, did not pass the correct host header to the proxy when accessing HTTPS sites. This affected many corporate proxies that perform HTTPS decryption, resulting in that the requests did not reach their target servers. In addition it caused the launcher to hang.The implementation is a patch of the node-patch library to set the defaultPort option based on the protocol of the URL. If a specific port is set in the URL, this will still override the defaultPort.
Steps to test
Place cypress behind a proxy that performs HTTPS decryption and launch cypress with
npx cypress open
.One such proxy is the
ntlm-proxy
part of https://github.com/bjowes/cypress-ntlm-auth :npx ntlm-proxy
. Note the ports used for configApiUrl and ntlmProxyUrl.xxx
with the port from configApiUrl)curl -d '{ "ntlmHosts": ["download.cypress.io", "registry.npmjs.org", "on.cypress.io"], "username": "dummy", "password": "dummy", "ntlmVersion": 2 }' -H 'Content-Type: application/json' http://127.0.0.1:xxx/ntlm-config
The call should return OK.
HTTP_PROXY=http://127.0.0.1:yyy npx cypress open
, make sure to replaceyyy
with the port from ntlmProxyUrl. The launcher will stall and requests to download.cypress.io, registry.npmjs.org and on.cypress.io will fail.Repeat step 3 with this PR applied, then the launcher shall work as intended. To test the proxy without HTTPS decryption, simply skip step 2.
How has the user experience changed?
The launcher now works as expected behind proxies that perform HTTPS decryption - for other users no change.
PR Tasks
cypress-documentation
? NA - No documentation needs updatingtype definitions
? NA - No APIs have been changed