Skip to content

Commit 2c686fd

Browse files
committed
http: flush stored header
`flushHeaders` should work for header written with `writeHead`. PR-URL: #1695 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 4e90c82 commit 2c686fd

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

lib/_http_outgoing.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -636,10 +636,11 @@ OutgoingMessage.prototype._flush = function() {
636636

637637
OutgoingMessage.prototype.flushHeaders = function() {
638638
if (!this._header) {
639-
// Force-flush the headers.
640639
this._implicitHeader();
641-
this._send('');
642640
}
641+
642+
// Force-flush the headers.
643+
this._send('');
643644
};
644645

645646
OutgoingMessage.prototype.flush = util.deprecate(function() {

test/parallel/test-http-flush-headers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const http = require('http');
55

66
const server = http.createServer();
77
server.on('request', function(req, res) {
8-
assert(req.headers['foo'], 'bar');
8+
assert.equal(req.headers['foo'], 'bar');
99
res.end('ok');
1010
server.close();
1111
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const http = require('http');
5+
6+
const server = http.createServer();
7+
8+
server.on('request', function(req, res) {
9+
res.writeHead(200, {'foo': 'bar'});
10+
res.flushHeaders();
11+
res.flushHeaders(); // Should be idempotent.
12+
});
13+
server.listen(common.PORT, common.localhostIPv4, function() {
14+
var req = http.request({
15+
method: 'GET',
16+
host: common.localhostIPv4,
17+
port: common.PORT,
18+
}, onResponse);
19+
20+
req.end();
21+
22+
function onResponse(res) {
23+
assert.equal(res.headers['foo'], 'bar');
24+
res.destroy();
25+
server.close();
26+
}
27+
});

0 commit comments

Comments
 (0)