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

Headers change from original case to all lowercase during cy.request() #2879

Closed
Robpizza opened this issue Dec 3, 2018 · 12 comments
Closed
Labels
stage: ready for work The issue is reproducible and in scope type: unexpected behavior User expected result, but got another

Comments

@Robpizza
Copy link

Robpizza commented Dec 3, 2018

Current behavior:

I use the "Authorization" header to authenticate a request but when I post a html form in cypress it changes all the HTTP headers to lowercase, so "Authorization" becomes "authorization" which is refused at backend.

so this is my browser
Image of browser
this is cypress
Image of cypress

Desired behavior:

I'd like the request headers to keep their capital letter because it causes issues😋

Steps to reproduce:

Make a small php file with a html form, and when submit print_r(getallheaders());

Versions

Cypress V3.1.2
NodeJS v8.11.4
Npm v6.4.1

I use Chrome v70.0.3538.110 on MacOS Mojave v10.14.1

@jennifer-shehane jennifer-shehane added the stage: ready for work The issue is reproducible and in scope label Dec 3, 2018
@Robpizza
Copy link
Author

Robpizza commented Dec 3, 2018

I tried it in NodeJS + Express and the headers are all converted to lowercase but when I request rawHeaders they are normal.

Request headers

{ authorization: '1234567890',
  authorisation: '1234567',
  'cache-control': 'no-cache',
  'postman-token': 'd9567be6-c426-4351-8746-f49b104aa149',
  'user-agent': 'PostmanRuntime/7.4.0',
  accept: '*/*',
  host: '0.0.0.0:7070',
  'accept-encoding': 'gzip, deflate',
  'content-length': '0',
  connection: 'keep-alive' }

Raw headers

[  'Authorization', '1234567890',
'Authorisation', '1234567',
'cache-control', 'no-cache',
'Postman-Token', 'd9567be6-c426-4351-8746-f49b104aa149',
'User-Agent', 'PostmanRuntime/7.4.0',
'Accept', '*/*',
'Host', '0.0.0.0:7070',
'accept-encoding', 'gzip, deflate',
'content-length', '0',
'Connection', 'keep-alive' ]

@jennifer-shehane jennifer-shehane added the type: unexpected behavior User expected result, but got another label Dec 4, 2018
@Robpizza
Copy link
Author

Robpizza commented Dec 4, 2018

Does Cypress use HTTP in NodeJS to send requests?
if so that could cause this problem, according to this Github issue.

@Robpizza
Copy link
Author

bump

@Robpizza
Copy link
Author

We changed our back-end 👍

@jennifer-shehane
Copy link
Member

Hey @Robpizza, the HTTP spec does define header fields as case insensitive - so servers should be case insensitive as well.

Each header field consists of a case-insensitive field name followed by a colon (":"), optional leading whitespace, the field value, and optional trailing whitespace.

But, I understand that not all servers may choose to behave in this way. I don't think it would be unreasonable to pass along the Header fields with the casings as they were originally requested, but as you said, I'm not sure how this is implemented.

@jennifer-shehane jennifer-shehane changed the title Headers become all lowercase Headers change from original case to all lowercase during cy.request() Jan 30, 2019
@jennifer-shehane
Copy link
Member

Cypress currently transforms all headers to be lowercase when testing using cy.request(), so if you are willing to update your server, ensure it does not care about casing of headers.

@jennifer-shehane
Copy link
Member

Hey @nhhockeyplayer, please see our main documentation here: https://docs.cypress.io

Cypress is a front end testing tool built for the modern web. We address the key pain points developers and QA engineers face when testing modern applications.

TypeScript doc: https://on.cypress.io/typescript-support

@jennifer-shehane
Copy link
Member

@nhhockeyplayer I'm sorry, I don't understand completely. What is happening that you want to stop happening? Where are you seeing behavior from Cypress exactly?

@jeffj6123
Copy link

jeffj6123 commented Sep 18, 2020

Hello,

I am also experiencing this issue but with cy.route where the response headers are being transformed to lowercase and modifying them. The following is the same semantics they use; casing and hyphens. This format is odd but I do not have control over changing the server that provides the response. Would there be any work around here?

        headers: {
            'TEST-HeaderName': 'some value',
        }

is changed to

"test-header-name" 

Cypress version is 4.12.1

@renanpupin
Copy link

I can confirm it's happening with the Authorization header.

@ReactQQ
Copy link

ReactQQ commented Dec 23, 2021

Any chances to make "headers converting" an option that could be set in cypress options?

@mjhenkes
Copy link
Member

The http spec specifies that headers should be case insensitive, as such we're closing this issue.

Each header field consists of a case-insensitive field name followed by a colon (":"), optional leading whitespace, the field value, and optional trailing whitespace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage: ready for work The issue is reproducible and in scope type: unexpected behavior User expected result, but got another
Projects
None yet
Development

No branches or pull requests

6 participants