Closed
Description
Current behavior:
Some of my website's HTTP requests are failing only in the Cypress browser (e.g. signing up for a new account). After debugging, it was discovered this was due to the response header returning a different content-type
in the Cypress browser.
Chrome browser:
content-type: application/json
Cypress browser (not running headlessly):
Content-type: application/json; charset=utf-8
Cypress is adding "charset=utf-8"
to the content-type
.
Desired behavior:
Return the same content-type
as the Chrome browser.
Versions
3.1.5
Chrome 72
Activity
[-]Cypress browser is adding "charset=utf-8" to the content-type in the response header[/-][+]Cypress browser adds "charset=utf-8" to the content-type in the response header[/+][-]Cypress browser adds "charset=utf-8" to the content-type in the response header[/-][+]Chrome Cypress browser adds "charset=utf-8" to the content-type in the response header[/+]yusinto commentedon Apr 2, 2019
I also encountered the same problem. Previously my app checks the Content-Type of the http response by doing a string comparison which fails. I refactored it so it checks the existence of the desired type instead:
I don't think you can always safely assume that browsers will only send 'application/json' in the Content-Type header. Hope that helps.
funatronics commentedon Apr 10, 2019
@yusinto yeah, that was my solution to this problem as well.
ludwikd commentedon May 31, 2019
In my case strange is that,
when running test on locally deployed (localhost) web page, the header is unchanged:
application/json
But when testing the same web app remotely deployed (s3 + CloudFront), the header is extended with
charset=utf-8
flotwig commentedon Jul 12, 2019
This is a symptom of ExpressJS (which Cypress uses for the internal proxy server) forcing
charset=utf-8
on all responses, which will be fixed by #4698.cypress-bot commentedon Jul 15, 2019
The code for this is done in cypress-io/cypress#4698, but has yet to be released.
We'll update this issue and reference the changelog when it's released.
cypress-bot commentedon Jul 29, 2019
Released in
3.4.1
.funatronics commentedon Jul 31, 2019
Thank you!