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

content-length header is lost under Cypress. #16469

Open
dvkruchinin opened this issue May 12, 2021 · 22 comments
Open

content-length header is lost under Cypress. #16469

dvkruchinin opened this issue May 12, 2021 · 22 comments
Labels
E2E Issue related to end-to-end testing existing workaround Reproducible Can be reproduced Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team. type: bug

Comments

@dvkruchinin
Copy link

dvkruchinin commented May 12, 2021

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

@dvkruchinin
Copy link
Author

Hello. Did you manage to view this issue?

@dvkruchinin
Copy link
Author

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.

@dvkruchinin dvkruchinin changed the title Content length is not returned from the test. content-length header is lost under Cypress. Jun 17, 2021
@dvkruchinin
Copy link
Author

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)

@adi518
Copy link

adi518 commented Jul 5, 2021

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.

@dvkruchinin
Copy link
Author

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.

@adi518
Copy link

adi518 commented Jul 22, 2021

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.

@dvkruchinin
Copy link
Author

Hi @jennifer-shehane,
Is there any update on this?

@adi518
Copy link

adi518 commented Jul 28, 2021

@dvkruchinin Maybe it's miraculously fixed in version 8.

@dvkruchinin
Copy link
Author

@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

@dennisoelkers
Copy link

I am seeing the same issue. Did anyone manage to work around this or read through the code to find the issue?

@adi518
Copy link

adi518 commented Nov 3, 2021

@dennisoelkers I posted a workaround just a few posts above.

@stfnlutter
Copy link

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 :)

@ferrisbuhler
Copy link

ferrisbuhler commented Jan 25, 2022

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).

@richard-viney
Copy link

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 🤷‍♂️

@sam060584
Copy link

sam060584 commented Mar 25, 2022

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!!

@estefafdez
Copy link

Any update on this one? Thanks!

@masciugo
Copy link

I am experiencing the same problem. Thanks for the workaround but it I hope it will fixed

@nicoladl
Copy link

The workaround works because the Content-Length is now part of the response headers.

Screenshot 2022-11-29 at 10 37 46

The issue now is that I receive this: SyntaxError: Unexpected end of JSON input
Screenshot 2022-11-29 at 10 37 51

@richard-viney
Copy link

richard-viney commented Jan 8, 2023

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?

@adam-harwood
Copy link

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.

@ojbravo
Copy link

ojbravo commented Jul 24, 2023

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!

@nagash77 nagash77 added E2E Issue related to end-to-end testing Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team. labels Jul 25, 2023
@dennisoelkers
Copy link

@jennifer-shehane: Is this ever going to get some attention? We are working around this bug for three years now and would like to get rid of that, as it is very subtle and irritating to anyone not aware of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E2E Issue related to end-to-end testing existing workaround Reproducible Can be reproduced Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team. type: bug
Projects
None yet
Development

No branches or pull requests