Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

visit() does not send user agent header as specified #3719

Closed
Songyu-Wang opened this issue Mar 15, 2019 · 5 comments · Fixed by #3920
Closed

visit() does not send user agent header as specified #3719

Songyu-Wang opened this issue Mar 15, 2019 · 5 comments · Fixed by #3920
Labels
type: unexpected behavior User expected result, but got another

Comments

@Songyu-Wang
Copy link
Contributor

Songyu-Wang commented Mar 15, 2019

Current behavior:

With the new feature in 3.2.0 that enables setting headers for visit(), "user agent" header is not correctly passed to server side

Desired behavior:

user agent header can be passed to server side as specified

Steps to reproduce: (app code and test code)

Using the following code:

cy.visit({
      url: '/',
      headers: {
        'User-Agent': 'bad browser',
        'hello': 'hi'
      }
    })

And observe server side receives something like this:
image

As shown above, header "hello" is correctly passed, therefore the header setting is recognized by cypress. However, header "User-Agent" is still my real browser which is the error

Versions

cypress 3.2.0

@flotwig
Copy link
Contributor

flotwig commented Mar 15, 2019

It's probably because the UA header gets clobbered in two places in request.coffee:

https://github.com/cypress-io/cypress/blob/develop/packages/server/lib/request.coffee#L267
https://github.com/cypress-io/cypress/blob/develop/packages/server/lib/request.coffee#L328

From a first glance, it looks like this is just Cypress trying to pass along the UA of the browser with the request. It'd probably be safe to change these lines to have and !headers["user-agent"] or similar to allow UA to be overridden.

Need to make sure we're normalizing headers to be lowercase before that can happen.

@jennifer-shehane
Copy link
Member

jennifer-shehane commented Mar 18, 2019

You can set the userAgent as a configuration value in your cypress.json file - https://on.cypress.io/configuration#Browser

There's some explanation on why we implemented it this way here: #364

headers lowercase issue: #2879

We should document this more clearly though within the cy.visit() doc though.
I created a new issue in our docs to document this here: cypress-io/cypress-documentation#1498. Our documentation is open source and contributions are welcome. 😄

@jennifer-shehane
Copy link
Member

After further discussion - we should probably also at least handle warning the user when passing a User-Agent header that there is another way to implement this (if not change the implementation to work altogether), so we reopened.

@cypress-bot cypress-bot bot added the stage: ready for work The issue is reproducible and in scope label Mar 19, 2019
@jennifer-shehane jennifer-shehane added the type: unexpected behavior User expected result, but got another label Mar 19, 2019
@cypress-bot cypress-bot bot added stage: pending release and removed stage: ready for work The issue is reproducible and in scope labels May 1, 2019
@cypress-bot
Copy link
Contributor

cypress-bot bot commented May 1, 2019

The code for this is done in cypress-io/cypress#3920, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented May 17, 2019

Released in 3.3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: unexpected behavior User expected result, but got another
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants