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

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 6
  • Comments: 21

Most upvoted comments

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.

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 am experiencing the same problem. Thanks for the workaround but it I hope it will fixed

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?

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

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