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

Comments

3 participants
@Songyu-Wang
Copy link
Contributor

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Member

commented Mar 19, 2019

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

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
You can’t perform that action at this time.