We were waiting for the release to use headers with cy.visit. We are happy it is implemented, however it still does not work correctly for our use case.
When using cy.visit() with headers it does not include them on redirects.
Having the given headers on all requests that started from cy.visit(). Possibly with a toggle for users that only want it on the first visit.
cy.visit({
url: http://tinyurl.com/1c2,
headers: {
HEADER1: "value1",
HEADER2: "value2"
}
})
When you check the network in the cypress browser it does not include them in the request headers from a redirect.
Tested on Windows 10
Cypress: 3.2.0
Browser: Chrome 72
HTTP clients don't normally re-use headers when they're redirected (besides things like Cookies and User-Agent, which are sent on every request). For that reason, this should probably be implemented as opt-in functionality, since it goes against how a browser would normally behave.
@flotwig can you research what cy.request() does - likely cy.visit() needs to follow the same behavior.
@flotwig can you research what
cy.request()does - likelycy.visit()needs to follow the same behavior.
I think cy.request has the same "issue".
cy.request appears to forward headers with followRedirect: true, which is the default. The following test will pass:
describe('', function() {
it('forwards headers', function() {
cy.request({
url: 'https://bit.ly/2U6JDFW', // 301 to http://myhttpheader.com/
headers: {
'test': 'foobarbazquuxquuz'
},
followRedirect: true,
}).then(function(res) {
expect(res.body).to.include('foobarbazquuxquuz')
})
})
})
@brian-mann should this be the default behavior for cy.visit as well?
I am experiencing this issue as well. I'm glad to see we are now able to add headers when visiting a page, but my team's admin pages redirect to a separate SSO endpoint to use those headers, and unfortunately these headers are not being forwarded and there is no way (that I know of) for me to intercept the redirect and re-insert the headers.
I'd like to add that while this may not be standard functionality for the browser (can someone confirm if this is true or not), it is possible for browser extensions or other software to offer functionality like this. I believe this is how my company (Amazon) deals with adding these headers - using some mechanism to add special headers for us to authenticate internally. It probably isn't desirable for this functionality to be default when adding headers to a visit command, but it would be great if there was an optional boolean we could use.
Most helpful comment
I'd like to add that while this may not be standard functionality for the browser (can someone confirm if this is true or not), it is possible for browser extensions or other software to offer functionality like this. I believe this is how my company (Amazon) deals with adding these headers - using some mechanism to add special headers for us to authenticate internally. It probably isn't desirable for this functionality to be default when adding headers to a visit command, but it would be great if there was an optional boolean we could use.