bhantol bhantol - 1 month ago 11
reST (reStructuredText) Question

why subsequent HTTP requests

My JavaScript makes that ajax call which retrieves a JSON array.

I am trying simulate long running HTTP REST call request that takes longer to return the results.

The way I do it is delay writing anything to the response object on the server side until 5 minutes elapsed since the request landed. After that I set the status to 200 and write the response with the JSON ending the stream.

Putting a breakpoint on the serve side I realize that the request shows up second time but the browser's Network tab does not show another request being made.

It may not be relevant but I am using

browsersync
middlewars to serve this JSON and write the bytes and end the response in
setTimeout()
.

setTimeout(()=> {
res.statusCode = 200;
res.write(data);
res.end();
});


Question:

Anyone has any explanation as to why this is happening ? And if there is a way to simulate this in another ways ?

O_Z O_Z
Answer

In most cases the browser should retry if connection is closed before response. This is a link to the details => HTTP spec Client Behavior if Server Prematurely Closes Connection

BTW it might help you use the chrome throttling options on the network section of dev tools (F12)