cy.request - Content-type header can't be set for POST and PUT requests
See original GitHub issueCurrent behaviour:
I’m passing to the cy.request
command the options object that contains the header Content-type
:
cy.request({
method: 'POST',
url: `${Cypress.env('RAILS_APP_URL')}/admin/api/clients`,
headers: {
'Content-Type': 'application/json; charset=utf-8',
},
body: {}
})
For some reason, the header is not sent to the server. In the console, I can verify that the request doesn’t have Content-Type
:
The same is true for PUT verb:
cy.request({
method: 'PUT',
url: `${Cypress.env('RAILS_APP_URL')}/admin/api/employees/54967`,
body: {},
headers: {
'Content-Type': 'application/json; charset=utf-8',
}
})
The only way I can force to set the content-type
header is to add to each URL .json
postfix eg. ${Cypress.env('RAILS_APP_URL')}/admin/api/clients.json
I can’t find any information in the docs that Content-Type
is ignored and won’t be set for POST/PUT request. When I set it for GET a request it is set correctly.
Desired behaviour:
When I set Content-Type
header in the cy.request
command, it is sent with the request.
Versions
cypress 4.7.0 operating system: Linux Ubuntu 18 LTS browser: Chrome 83
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:7 (2 by maintainers)
Top Results From Across the Web
request
A request body to be sent in the request. Cypress sets the Accepts request header and serializes the response body by the encoding...
Read more >cypress-io/cypress - Gitter
When making a cy.request(method: "POST"), it seems to be executed and it can be logged and everything, but it does not appear in...
Read more >Test with cypress an custom HTTP Headers
Create a login() inside commands.js and use cy.request() to login to system and add the headers. Also before the test, I have run...
Read more >Cypress request and cookies | Better world by better software
While running the Cypress tests you can make requests to the backend with full set of the page's cookies using the cy.request command....
Read more >Content-Type - HTTP - MDN Web Docs - Mozilla
In requests, (such as POST or PUT ), the client tells the server what ... values can't contain a CORS-unsafe request header byte:...
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
@jennifer-shehane I only noticed one difference that I can reproduce. In case of your request, there is no
referer
header sent. In case of request to our API, thereferer
is always sent. It seems connected. When the request headers containsreferer
header, theContent-Type
is not sent when set as an option.As far as I can see our API sends
Referrer-Policy
header set tostrict-origin-when-cross-origin
Can we override referer? I dont want Referer like localhost:port/_cypress… I want to set this to say https://jira.myjira.com