Skip to content

Chrome Cypress browser adds "charset=utf-8" to the content-type in the response header #3650

Closed
@funatronics

Description

@funatronics

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

changed the title [-]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[/+] on Mar 5, 2019
changed the title [-]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[/+] on Mar 7, 2019
yusinto

yusinto commented on Apr 2, 2019

@yusinto

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:

// wrong
response.headers.get('Content-Type') === 'application/json'

// right
response.headers.get('Content-Type').includes('application/json')

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

funatronics commented on Apr 10, 2019

@funatronics
Author

@yusinto yeah, that was my solution to this problem as well.

ludwikd

ludwikd commented on May 31, 2019

@ludwikd

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

self-assigned this
on Jul 12, 2019
flotwig

flotwig commented on Jul 12, 2019

@flotwig
Contributor

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

cypress-bot commented on Jul 15, 2019

@cypress-bot
Contributor

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

cypress-bot commented on Jul 29, 2019

@cypress-bot
Contributor

Released in 3.4.1.

funatronics

funatronics commented on Jul 31, 2019

@funatronics
Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @flotwig@jennifer-shehane@yusinto@funatronics@ludwikd

    Issue actions

      Chrome Cypress browser adds "charset=utf-8" to the content-type in the response header · Issue #3650 · cypress-io/cypress