cypress
cypress copied to clipboard
content-length header is lost under Cypress.
Current behavior
When using Cypress, no content-length
header is returned.
This error is not reproduced when using the functionality without Cypress.
Desired behavior
Content length is returned.
Test code to reproduce
git clone https://github.com/dvkruchinin/cvat.git
cd cvat
git checkout case77-for-cypress-issue
docker-compose -f docker-compose.yml -f docker-compose.dev.yml build
docker-compose up -d
docker exec -it cvat bash -ic 'python3 ~/manage.py createsuperuser'
user: admin
email: <can leave it empty>
password: 12qwaszx
cd tests
npm ci
npx cypress open
run the test actions_objects2/case_77_intelligent_scissors.js
For checking without Cypress:
Open Chrome
Go to http://localhost:8080
Login as admin
password 12qwaszx
And reproduce the actions from the test
Versions
Cypress version: 6.4.0, 7.3.0 Browser: Chome Version 90.0.4430.93 (Official Build) (64-bit) OS: 20.04.1-Ubuntu
Hello. Did you manage to view this issue?
At the same time test
cy.request('/opencv/opencv.js').then((response) => {
expect(response.status).to.be.equal(200);
expect(response.headers).to.have.property('content-length');
});
Works successfully. Property content-length
is present.
Please tell me why in cypress Transfer-Encoding: chunked
when accessing a static js file? Is there any way to change this? This is probably why Content-Length
is not returned. Requests are sent the same (I mean through Cypress and without it)
I have a chunked blob response and the Content-Length
is missing. I think it's related to this issue. I worked around it by modifying the response headers, but it's pretty bad.
I have a chunked blob response and the
Content-Length
is missing. I think it's related to this issue. I worked around it by modifying the response headers, but it's pretty bad.
Hello @adi518, Can I ask you to tell me how you managed to get around this problem? In the code of your application? In the Cypress test? If in the test, how? Thank you very much.
Here's an example, it goes in your Cypress test code:
cy.intercept( 'GET', 'https://foobar.com/media.mp4', (req) => {
req.continue((res) => {
// monkey patch content-length, since cypress has a bug
// where it won't pass this property to the response.
const contentLength = 123456;
res.headers['Content-Length'] = String(contentLength);
});
}
).as('mediaRequest');
Notice you'll have to update it when you change your mock or things can/will break. I think it might be possible to make this seamless by reading your mock with fs.readFileSync
and calculating the content length.
Hi @jennifer-shehane, Is there any update on this?
@dvkruchinin Maybe it's miraculously fixed in version 8.
@dvkruchinin Maybe it's miraculously fixed in version 8.
Unfortunately it is still reproduced. With Cypress:
Content-Encoding: gzip
content-type: application/javascript
date: Wed, 28 Jul 2021 13:59:50 GMT
etag: "5c818ebc79850"
last-modified: Tue, 27 Jul 2021 11:10:44 GMT
referrer-policy: same-origin
server: Apache
Vary: Origin, Accept-Encoding
x-content-type-options: nosniff
Without Cypress:
Content-Length: 9060818
Content-Type: application/javascript
Date: Wed, 28 Jul 2021 14:02:50 GMT
Etag: "5c818ebc79850"
Last-Modified: Tue, 27 Jul 2021 11:10:44 GMT
Referrer-Policy: same-origin
Server: Apache
Vary: Origin
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
I am seeing the same issue. Did anyone manage to work around this or read through the code to find the issue?
@dennisoelkers I posted a workaround just a few posts above.
Just ran into the same issue, not trivial to find at all. Thanks @dvkruchinin for having reported this and @adi518 for the workaround.
Hoping of course for a fix :)
Thanks for the workaround, adi518.
A little hint for all non-network-pros (like me): Take care to spell the header name 'Content-Length' correctly (with C and L upper case). Writing it lower case (as all the debug tools suggest) will make the solution fail (at least in my case it was).
Still seeing this in [email protected]
. Fortunately the workaround is fine for the app I work on, but it is still rather strange the way this header is killed off by Cypress 🤷♂️
Modifying the response header workaround is not working in case of content-length >1024
, header is getting changed to Transfer-Encoding": "chunked"
.I also tried modifying the request header "Accept-Encoding" to 'identity"
that also did not work.
I am unable to load the application through Cypress. Any help appreciated!!
Any update on this one? Thanks!
I am experiencing the same problem. Thanks for the workaround but it I hope it will fixed
The workaround works because the Content-Length
is now part of the response headers.
The issue now is that I receive this: SyntaxError: Unexpected end of JSON input
Still experiencing this in 12.3.0, and the cy.intercept
workaround above has started being unreliable in some cases for us, which we fixed by using req.on("after:response")
instead of req.continue()
:
req.on("after:response", (response) => {
response.headers["Content-Length"] = "...";
});
Is a maintainer able to provide any insight on this issue or some guidance as to how a new contributor might appproach fixing it?
Bump, is any maintainer able to provide a very rough guide on where to start looking for this issue? I'm really motivated to solve it, happy to open a PR, just some place to start would help a lot. I'm looking and Cypress is big.
I have this issue for the past 6 months. I just upgrades to 12.17.2 in hopes of a fix, but no luck. Neither of the work-arounds worked for me either. Definitely hoping for a fix!