Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-flush-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
27 changes: 27 additions & 0 deletions test/parallel/test-http-flush-response-headers.js
Original file line number Diff line number Diff line change
@@ -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();
}
});