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`.
  • Loading branch information
vkurchatkin committed May 13, 2015
1 parent 7693705 commit 4deb05b
Show file tree
Hide file tree
Showing 3 changed files with 32 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(req.headers['foo'] === 'bar');
res.end('ok');
server.close();
});
Expand Down
28 changes: 28 additions & 0 deletions test/parallel/test-http-flush-response-headers.js
Original file line number Diff line number Diff line change
@@ -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();
}

});

0 comments on commit 4deb05b

Please sign in to comment.