diff options
author | Vladimir Kurchatkin <vladimir.kurchatkin@gmail.com> | 2015-05-13 18:52:49 +0300 |
---|---|---|
committer | Vladimir Kurchatkin <vladimir.kurchatkin@gmail.com> | 2015-05-29 16:19:12 +0300 |
commit | 2c686fd3ce4b68a1d7955da9c157baf52ab25285 (patch) | |
tree | ad549c466d608e25c4d25f7f34a7f15754d7ee4a | |
parent | 4e90c82cdb9d69dbffe340e7ac9bd1b4b6e1d781 (diff) | |
download | nodejs-2c686fd3ce4b68a1d7955da9c157baf52ab25285.tar.gz nodejs-2c686fd3ce4b68a1d7955da9c157baf52ab25285.tar.bz2 nodejs-2c686fd3ce4b68a1d7955da9c157baf52ab25285.zip |
http: flush stored header
`flushHeaders` should work for header written
with `writeHead`.
PR-URL: https://github.com/nodejs/io.js/pull/1695
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
-rw-r--r-- | lib/_http_outgoing.js | 5 | ||||
-rw-r--r-- | test/parallel/test-http-flush-headers.js | 2 | ||||
-rw-r--r-- | test/parallel/test-http-flush-response-headers.js | 27 |
3 files changed, 31 insertions, 3 deletions
diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index 6ebf716fa..952b2ed08 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -636,10 +636,11 @@ OutgoingMessage.prototype._flush = function() { OutgoingMessage.prototype.flushHeaders = function() { if (!this._header) { - // Force-flush the headers. this._implicitHeader(); - this._send(''); } + + // Force-flush the headers. + this._send(''); }; OutgoingMessage.prototype.flush = util.deprecate(function() { diff --git a/test/parallel/test-http-flush-headers.js b/test/parallel/test-http-flush-headers.js index da1bd24c5..e3c9761cf 100644 --- a/test/parallel/test-http-flush-headers.js +++ b/test/parallel/test-http-flush-headers.js @@ -5,7 +5,7 @@ const http = require('http'); const server = http.createServer(); server.on('request', function(req, res) { - assert(req.headers['foo'], 'bar'); + assert.equal(req.headers['foo'], 'bar'); res.end('ok'); server.close(); }); diff --git a/test/parallel/test-http-flush-response-headers.js b/test/parallel/test-http-flush-response-headers.js new file mode 100644 index 000000000..76e739741 --- /dev/null +++ b/test/parallel/test-http-flush-response-headers.js @@ -0,0 +1,27 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const http = require('http'); + +const server = http.createServer(); + +server.on('request', function(req, res) { + res.writeHead(200, {'foo': 'bar'}); + res.flushHeaders(); + res.flushHeaders(); // Should be idempotent. +}); +server.listen(common.PORT, common.localhostIPv4, function() { + var req = http.request({ + method: 'GET', + host: common.localhostIPv4, + port: common.PORT, + }, onResponse); + + req.end(); + + function onResponse(res) { + assert.equal(res.headers['foo'], 'bar'); + res.destroy(); + server.close(); + } +}); |