Note that there are some explanatory texts on larger screens.

plurals
  1. PONode.js: pipe stream to response freezes over HTTPS
    primarykey
    data
    text
    <p>I'm trying to use <a href="http://senchalabs.github.com/connect/" rel="nofollow">Connect</a> to serve static content, but with large files (> 40KB), a first chunk of 40,960 bytes is sent (sometimes 32,940 bytes), then the transfer sleeps for 2 minutes, then the transfer finishes. I found out that it happens when I pipe a stream to the response (this is how Connect sends the response).</p> <p>Here is a code the reproduces this, on Node 0.6.2, on Windows and Linux, with a 48,980 bytes file:</p> <pre><code>var fs = require( "fs" ), https = require("https"); var privateKey = fs.readFileSync( 'privatekey.pem' ).toString(); var certificate = fs.readFileSync( 'certificate.pem' ).toString(); var options = {key: privateKey, cert: certificate}; var server = https.createServer( options, function( req, res ) { var path = __dirname + "/public" + req.url; fs.stat(path, function(err, stat){ if( err ) { res.writeHead(404, {'Content-Type': 'text/html'}); res.end(""+err); } else { res.writeHead(200, { 'Content-Type': 'text/html', 'Content-Length': stat.size}); var stream = fs.createReadStream(path); stream.pipe(res); } } ); } ).listen(8364); </code></pre> <p>With <code>fs.readFile</code>, I cannnot reproduce :</p> <pre><code>var fs = require( "fs" ), https = require("https"); var privateKey = fs.readFileSync( 'privatekey.pem' ).toString(); var certificate = fs.readFileSync( 'certificate.pem' ).toString(); var options = {key: privateKey, cert: certificate}; var server = https.createServer( options, function( req, res ) { fs.readFile(__dirname + "/public" + req.url, function(err, data){ if( err ) { res.writeHead(404, {'Content-Type': 'text/html'}); res.end(""+err); } else { res.writeHead(200, { 'Content-Type': 'text/html', 'Content-Length': data.length}); res.end(data); } } ); } ).listen(8364); </code></pre> <p>Did I do something wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

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