diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index 6ebf716fab9fb8..952b2ed082644a 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 da1bd24c54a884..e3c9761cff5d34 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 00000000000000..76e739741cb2db --- /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(); + } +});