diff options
author | Brian White <mscdex@mscdex.net> | 2017-06-07 11:25:24 -0400 |
---|---|---|
committer | Brian White <mscdex@mscdex.net> | 2017-06-12 20:42:46 -0400 |
commit | c4fc7d90eddbdb23d814a38192e6979f8fc285a7 (patch) | |
tree | 397aa47668cbd44da57d93428076733ae78cd3ac /benchmark/fixtures | |
parent | 77d575d0057692413f0c26ad90425077c40f339f (diff) | |
download | node-new-c4fc7d90eddbdb23d814a38192e6979f8fc285a7.tar.gz |
http: always cork outgoing writes
PR-URL: https://github.com/nodejs/node/pull/13522
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Diffstat (limited to 'benchmark/fixtures')
-rw-r--r-- | benchmark/fixtures/simple-http-server.js | 62 |
1 files changed, 29 insertions, 33 deletions
diff --git a/benchmark/fixtures/simple-http-server.js b/benchmark/fixtures/simple-http-server.js index 1dda98e9f2..854d249ac8 100644 --- a/benchmark/fixtures/simple-http-server.js +++ b/benchmark/fixtures/simple-http-server.js @@ -27,13 +27,14 @@ module.exports = http.createServer(function(req, res) { dom.add(res); } - // URL format: /<type>/<length>/<chunks>/<responseBehavior> + // URL format: /<type>/<length>/<chunks>/<responseBehavior>/chunkedEnc var params = req.url.split('/'); var command = params[1]; var body = ''; var arg = params[2]; var n_chunks = parseInt(params[3], 10); var resHow = (params.length >= 5 ? params[4] : 'normal'); + var chunkedEnc = (params.length >= 6 && params[5] === 'false' ? false : true); var status = 200; var n, i; @@ -95,48 +96,43 @@ module.exports = http.createServer(function(req, res) { // example: http://localhost:port/bytes/512/4 // sends a 512 byte body in 4 chunks of 128 bytes - if (n_chunks > 0) { - switch (resHow) { - case 'setHeader': - res.statusCode = status; - res.setHeader('Content-Type', 'text/plain'); + var len = body.length; + switch (resHow) { + case 'setHeader': + res.statusCode = status; + res.setHeader('Content-Type', 'text/plain'); + if (chunkedEnc) res.setHeader('Transfer-Encoding', 'chunked'); - break; - case 'setHeaderWH': - res.setHeader('Content-Type', 'text/plain'); + else + res.setHeader('Content-Length', len.toString()); + break; + case 'setHeaderWH': + res.setHeader('Content-Type', 'text/plain'); + if (chunkedEnc) res.writeHead(status, { 'Transfer-Encoding': 'chunked' }); - break; - default: + else + res.writeHead(status, { 'Content-Length': len.toString() }); + break; + default: + if (chunkedEnc) { res.writeHead(status, { 'Content-Type': 'text/plain', 'Transfer-Encoding': 'chunked' }); - } - // send body in chunks - var len = body.length; + } else { + res.writeHead(status, { + 'Content-Type': 'text/plain', + 'Content-Length': len.toString() + }); + } + } + // send body in chunks + if (n_chunks > 1) { var step = Math.floor(len / n_chunks) || 1; - - for (i = 0, n = (n_chunks - 1); i < n; ++i) { + for (i = 0, n = (n_chunks - 1); i < n; ++i) res.write(body.slice(i * step, i * step + step)); - } res.end(body.slice((n_chunks - 1) * step)); } else { - switch (resHow) { - case 'setHeader': - res.statusCode = status; - res.setHeader('Content-Type', 'text/plain'); - res.setHeader('Content-Length', body.length.toString()); - break; - case 'setHeaderWH': - res.setHeader('Content-Type', 'text/plain'); - res.writeHead(status, { 'Content-Length': body.length.toString() }); - break; - default: - res.writeHead(status, { - 'Content-Type': 'text/plain', - 'Content-Length': body.length.toString() - }); - } res.end(body); } }); |