From 2c686fd3ce4b68a1d7955da9c157baf52ab25285 Mon Sep 17 00:00:00 2001 From: Vladimir Kurchatkin Date: Wed, 13 May 2015 18:52:49 +0300 Subject: 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 --- lib/_http_outgoing.js | 5 +++-- test/parallel/test-http-flush-headers.js | 2 +- test/parallel/test-http-flush-response-headers.js | 27 +++++++++++++++++++++++ 3 files changed, 31 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 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(); + } +}); -- cgit v1.2.3