cypress icon indicating copy to clipboard operation
cypress copied to clipboard

content-length header is lost under Cypress.

Open dvkruchinin opened this issue 3 years ago • 22 comments

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 avatar May 12 '21 08:05 dvkruchinin

Hello. Did you manage to view this issue?

dvkruchinin avatar Jun 16 '21 10:06 dvkruchinin

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 avatar Jun 17 '21 09:06 dvkruchinin

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)

dvkruchinin avatar Jun 25 '21 06:06 dvkruchinin

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.

adi518 avatar Jul 05 '21 12:07 adi518

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.

dvkruchinin avatar Jul 22 '21 10:07 dvkruchinin

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.

adi518 avatar Jul 22 '21 12:07 adi518

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

dvkruchinin avatar Jul 28 '21 08:07 dvkruchinin

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

adi518 avatar Jul 28 '21 09:07 adi518

@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

dvkruchinin avatar Jul 28 '21 14:07 dvkruchinin

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

dennisoelkers avatar Nov 03 '21 08:11 dennisoelkers

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

adi518 avatar Nov 03 '21 09:11 adi518

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

stfnlutter avatar Jan 25 '22 09:01 stfnlutter

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

ferrisbuhler avatar Jan 25 '22 10:01 ferrisbuhler

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

richard-viney avatar Mar 14 '22 09:03 richard-viney

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

sam060584 avatar Mar 25 '22 23:03 sam060584

Any update on this one? Thanks!

estefafdez avatar Sep 08 '22 12:09 estefafdez

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

masciugo avatar Nov 24 '22 11:11 masciugo

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

nicoladl avatar Nov 29 '22 09:11 nicoladl

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?

richard-viney avatar Jan 08 '23 22:01 richard-viney

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.

adam-harwood avatar Mar 07 '23 05:03 adam-harwood

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!

ojbravo avatar Jul 24 '23 23:07 ojbravo