Skip to content

Commit

Permalink
http: flush stored header
Browse files Browse the repository at this point in the history
`flushHeaders` should work for header written
with `writeHead`.

PR-URL: nodejs/node#1695
Reviewed-By: Ben Noordhuis <[email protected]>
  • Loading branch information
vkurchatkin authored and andrewdeandrade committed Jun 3, 2015
1 parent b2ce987 commit 25b8aeb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
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();
}
});

0 comments on commit 25b8aeb

Please sign in to comment.