question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Large XHR response objects can exceed the maximum header size.

See original GitHub issue

If I respond to route with a very large object, tests waiting for that response will fail with ERR_EMPTY_RESPONSE

cy
  .server()
  .route("POST", /route/, reallyLargeObject).as("willFail")
  .get(".submit").click()
  .wait("@willFail")

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:6
  • Comments:18 (5 by maintainers)

github_iconTop GitHub Comments

11reactions
tolicodescommented, Aug 15, 2018

hah just found a super simple solution: before I had

cy.fixture(`${endpoint}.json`).as(`fixture${endpoint}`);
cy.route(path, `@fixture${endpoint}.json`)
    .as(endpoint);

now:

cy.route(path, `fixture:${endpoint}.json`)
    .as(endpoint);

Cleaner and it works 😃

5reactions
ankricommented, May 1, 2018

Thank you for your suggestions.

For guys coming from google. Here is our workaround:

put this in e.g. integration/utils/loadLargeFixture.js

export default function loadLargeFixture(url, response, method = 'GET') {
  return cy.route({
    url,
    method,
    onRequest: xhr => {
      const originalOnLoad = xhr.xhr.onload;
      xhr.xhr.onload = function() {
        Object.defineProperty(this, 'response', {
          writable: true
        });
        this.response = response;
        originalOnLoad.apply(this, xhr);
      };
    }
  });
}

Import the json and the loadLargeFixture function in your test:

import largeFixture from '../fixtures/veryLargeJson.json';
import loadLargeFixture from '../utils/loadLargeFixture';

describe('demo', () => {
  it('should work with large fixture', () => {
    cy.server();
    loadLargeFixture('/api/large', largeFixture).as('data');
    // do stuff
    cy.wait('@data')
    // do stuff
  });
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Maximum on HTTP header values? - Stack Overflow
No, HTTP does not define any limit. However most web servers do limit size of headers they accept. For example in Apache default...
Read more >
431 Request Header Fields Too Large - HTTP - MDN Web Docs
431 can be used when the total size of request headers is too large, or when a single header field is too large....
Read more >
HTTP Response Header Size Limits | Max Chadwick
Their docs state a limit of 8192 bytes for response cookies, for example, citing CDN restrictions… Cookies are explicitly restricted to 8192 ...
Read more >
Request and response behavior for Amazon S3 origins
The maximum length of a request, including the path, the query string (if any), and headers, is 20,480 bytes. CloudFront constructs a URL...
Read more >
XMLHttpRequest - The Modern JavaScript Tutorial
URL – the URL to request, a string, can be URL object. ... got ${xhr.response.length} bytes`); // response is the server response }...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found