Delayed 304 responses when using proxy #4298
When a page loads resources, and the resources have been loaded before, the web server returns a 304 response. When running Cypress without proxy, this works fine. When running Cypress with proxy, there is a 5 second delay before the response reaches the browser.
There should be no additional delay on 304 responses with a proxy.
Steps to reproduce: (app code and test code)
I have created a minimal demo for the issue. Please see:
The README contains instruction on using the demo.
In this simplistic case, the tests still pass. In my real scenario I am testing an Angular app with many more resources. The tests fail nearly every time due to timeout caused by delayed 304 responses.
Tested with Cypress 3.3.1 on Windows 10 and OS X 10.14.4.
Since the proxy I use is made by me (and based on the
The only thing the
Personally I can live with my workaround but I believe that it is not an unusual approach by proxies to always set
The text was updated successfully, but these errors were encountered:
Note that the workaround is not implemented exactly as I originally described. The published workaround checks if there are any response filters registered in the proxy (response filters are used to modify the response content). If there aren't (which there won't be in case of cypress-ntlm-auth) the transfer encoding is left as it was in the response from the server.
The 5 seconds thing being from 3.3.0 turned out to be a red herring, this issue is present at least as early as Cypress 3.2.0.
I recorded a few scenarios, all in Cypress 3.2.0:
Trying to see if I can localize the issue to a particular part of the proxy layer now.
Good progress @flotwig! I suspected that this issues was present also in earlier releases.
Did you consider the possibility that this may not be a proxy issue - maybe the same delay would occur with cache and chunked even without the proxy. In my case, the proxy causes chunked encoding so those go hand in hand, but it could just as well occur without a proxy. Just a hunch
Yeah, you're probably right in that it's not specific to proxies.
I recorded the conversations between the browser <-> Cypress <-> the mitm proxy:
Conversation between the browser and Cypress:
Conversation between Cypress and the chunked proxy:
Conversation between the chunked proxy and the server:
I think that
EDIT: This Node.js test seems to suggest that this is expected: https://github.com/nodejs/node/blob/8b4af64f50c5e41ce0155716f294c24ccdecad03/test/parallel/test-http-chunked-304.js#L58-L63
Yeah, found that in RFC 7230 section 3.3.3 point 1. I think the RFC is a bit too permissive - you can put any header you like on a 304 response, but you can’t send a body. That is a good recipe to confuse developers... It would probably have been easier if certain headers were simply not allowed in 304 responses (and similar non body responses)
But as it stands, I assume cypress needs to ignore those headers when parsing 304 responses.