From a486d0c255880041c27e7cb80dd216c9ab228fbd Mon Sep 17 00:00:00 2001 From: Vladimir Kurchatkin Date: Wed, 13 May 2015 18:52:49 +0300 Subject: [PATCH] http: flush stored header `flushHeaders` should work for header written with `writeHead`. --- lib/_http_outgoing.js | 5 ++-- test/parallel/test-http-flush-headers.js | 2 +- .../test-http-flush-response-headers.js | 28 +++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 test/parallel/test-http-flush-response-headers.js diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index bfebef21b69af6..9c8c928d94c960 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 ede0fa52021233..59205a41f695f9 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..170194a05c13c0 --- /dev/null +++ b/test/parallel/test-http-flush-response-headers.js @@ -0,0 +1,28 @@ +'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(); +}); +server.listen(common.PORT, '127.0.0.1', function() { + var req = http.request({ + method: 'GET', + host: '127.0.0.1', + port: common.PORT, + }, onResponse); + + req.end(); + + function onResponse(res) { + assert.equal(res.headers['foo'], 'bar'); + res.destroy(); + server.close(); + } + +});