Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http: add flushHeaders and deprecate flush #1156

Closed
wants to merge 1 commit into from
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
4 changes: 2 additions & 2 deletions doc/api/http.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ the client should send the request body.
Emitted when the request has been aborted by the client. This event is only
emitted on the first call to `abort()`.

### request.flush()
### request.flushHeaders()

Flush the request headers.

Expand All @@ -875,7 +875,7 @@ call `request.end()` or write the first chunk of request data. It then tries
hard to pack the request headers and data into a single TCP packet.

That's usually what you want (it saves a TCP round-trip) but not when the first
data isn't sent until possibly much later. `request.flush()` lets you bypass
data isn't sent until possibly much later. `request.flushHeaders()` lets you bypass
the optimization and kickstart the request.

### request.write(chunk[, encoding][, callback])
Expand Down
6 changes: 5 additions & 1 deletion lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,10 +630,14 @@ OutgoingMessage.prototype._flush = function() {
};


OutgoingMessage.prototype.flush = function() {
OutgoingMessage.prototype.flushHeaders = function() {
if (!this._header) {
// Force-flush the headers.
this._implicitHeader();
this._send('');
}
};

OutgoingMessage.prototype.flush = util.deprecate(function() {
this.flushHeaders();
}, 'flush is deprecated. Use flushHeaders instead.');
20 changes: 20 additions & 0 deletions test/parallel/test-http-flush-headers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const http = require('http');

const server = http.createServer();
server.on('request', function(req, res){
assert(req.headers['foo'], 'bar');
res.end('ok');
server.close();
});
server.listen(common.PORT, '127.0.0.1', function() {
let req = http.request({
method: 'GET',
host: '127.0.0.1',
port: common.PORT,
});
req.setHeader('foo', 'bar');
req.flushHeaders();
});