Browse Source

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 <info@bnoordhuis.nl>
v2.3.1-release
Vladimir Kurchatkin 10 years ago
parent
commit
2c686fd3ce
  1. 5
      lib/_http_outgoing.js
  2. 2
      test/parallel/test-http-flush-headers.js
  3. 27
      test/parallel/test-http-flush-response-headers.js

5
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() {

2
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();
});

27
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();
}
});
Loading…
Cancel
Save