Modify headers and status code but not stubbing response
See original GitHub issueI have an XHR request that responds normally with a status 200 and some data. There is one case where the response is enriched with some header data. I want to simulate this case.
This is the mock setup:
cy.server().route({
method: 'POST',
url: /some-url/,
headers: { key: 'value' }
});
The resulting call is a non stubbed call but also the key: value
headers are missing. They are not missing when I add a stubbed response to the route config.
The same happens with status
.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:12 (4 by maintainers)
Top Results From Across the Web
How do I set the status code of response when stubbing ...
My challenge now is that the server is getting stubbed with the code below, but I would like to stub not just the...
Read more >Stub response - ModHeader
Click on the Edit response button and enter the stub response status code, body, and headers. Click Save when you are done.
Read more >Returning stubbed HTTP responses to specific requests
HTTP methods currently supported are: GET, POST, PUT, DELETE, HEAD, TRACE, OPTIONS . You can specify ANY if you want the stub mapping...
Read more >Modify Headers | Requestly
Modify request and response headers in a few simple clicks. ... Edit Content-Type, Status Code, and Body of the Response on our Server....
Read more >If-Modified-Since header not working
I have not made any changes to contact metadata but it is still returning metadata for contact instead of HTTP/1.1 304 Not Modified...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I would agree that it would be a very useful feature. For example on our project we rely on the Cloudfront
cloudfront-viewer-country
header to geolocate our users so I would like to add that header when mocking the page request without modifying anything else in the response. Without it, I can’t think of any other way to test our geolocation feature.The features requested in this issue are now possible as part of
cy.route2()
.cy.route2()
is currently experimental and requires being enabled by passing"experimentalNetworkStubbing": true
through your Cypress configuration. This will eventually be merged in as part of our standard API.Please see the
cy.route2()
docs for full details: https://on.cypress.io/route2If you encounter any issues or unexpected behavior while using
cy.route2()
we encourage you to open a new issue so that we can work out all the issues before public release. Thanks!