Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to set a timeout specifically dealing with the absence of a continue event for a node.js http.ClientRequest object
    text
    copied!<p>I am trying to configure a client in node.js that will send data after several seconds if a 100-continue response is not received, but was requested by the client. The snippet below does that. However, if there is for some reason inactivity on the socket after I receive a continue event and start sending data, but before I call req.end(), then again this timeout is hit and the code therein executed. As such, while this is useful to monitor activity on the socket after I start sending data, it's not good for the problem I'm trying to solve -- send the data even if I don't receive a continue event. I've scrubbed the node.js documentation, and while I found the <a href="http://nodejs.org/api/http.html#http_event_continue" rel="nofollow">section describing how to listen for a continue event</a>, as well as the <a href="http://nodejs.org/api/net.html#net_socket_settimeout_timeout_callback" rel="nofollow">section describing how to set a timeout</a>, I can't find any information on setting a timeout specifically when waiting for a continue request. Any bright ideas?</p> <pre><code>req.on('socket', function(socket) { var timeout = 5000 socket.setTimeout(timeout); socket.on('timeout', function() { console.log('100-continue not received. Sending data anyway...'); fs.createReadStream(filepath, byte_range) .pipe(req, {end: false}).on('end', function() { req.end(); }); }); }); req.on('continue', function() { console.log('100-continue received. Sending data...'); fs.createReadStream(filepath, byte_range) .pipe(req, { end: false }).on('end', function() { req.end(); }); }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload