Skip to content

Commit b2e00e3

Browse files
yosuke-furukawabnoordhuis
authored andcommitted
http: add flushHeaders and deprecate flush
PR-URL: #1156 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Christian Tellnes <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent 68d4bed commit b2e00e3

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

doc/api/http.markdown

+2-2
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ the client should send the request body.
866866
Emitted when the request has been aborted by the client. This event is only
867867
emitted on the first call to `abort()`.
868868

869-
### request.flush()
869+
### request.flushHeaders()
870870

871871
Flush the request headers.
872872

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

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

881881
### request.write(chunk[, encoding][, callback])

lib/_http_outgoing.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -630,10 +630,14 @@ OutgoingMessage.prototype._flush = function() {
630630
};
631631

632632

633-
OutgoingMessage.prototype.flush = function() {
633+
OutgoingMessage.prototype.flushHeaders = function() {
634634
if (!this._header) {
635635
// Force-flush the headers.
636636
this._implicitHeader();
637637
this._send('');
638638
}
639639
};
640+
641+
OutgoingMessage.prototype.flush = util.deprecate(function() {
642+
this.flushHeaders();
643+
}, 'flush is deprecated. Use flushHeaders instead.');
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
server.on('request', function(req, res){
8+
assert(req.headers['foo'], 'bar');
9+
res.end('ok');
10+
server.close();
11+
});
12+
server.listen(common.PORT, '127.0.0.1', function() {
13+
let req = http.request({
14+
method: 'GET',
15+
host: '127.0.0.1',
16+
port: common.PORT,
17+
});
18+
req.setHeader('foo', 'bar');
19+
req.flushHeaders();
20+
});

0 commit comments

Comments
 (0)