question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Modify headers and status code but not stubbing response

See original GitHub issue

I 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:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
loicplairecommented, May 4, 2018

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.

0reactions
jennifer-shehanecommented, Oct 21, 2020

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/route2

If 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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found