From b2e00e38dcac23cf564636e8fad880829489286c Mon Sep 17 00:00:00 2001 From: Yosuke Furukawa Date: Sat, 14 Mar 2015 16:24:07 +0900 Subject: [PATCH] http: add flushHeaders and deprecate flush PR-URL: https://github.com/iojs/io.js/pull/1156 Reviewed-By: Ben Noordhuis Reviewed-By: Christian Tellnes Reviewed-By: Colin Ihrig Reviewed-By: Jeremiah Senkpiel --- doc/api/http.markdown | 4 ++-- lib/_http_outgoing.js | 6 +++++- test/parallel/test-http-flush-headers.js | 20 ++++++++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 test/parallel/test-http-flush-headers.js diff --git a/doc/api/http.markdown b/doc/api/http.markdown index c4af8f407c..de8e7eb6dd 100644 --- a/doc/api/http.markdown +++ b/doc/api/http.markdown @@ -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. @@ -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]) diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index f6144ba6a6..3102261755 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -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.'); diff --git a/test/parallel/test-http-flush-headers.js b/test/parallel/test-http-flush-headers.js new file mode 100644 index 0000000000..ede0fa5202 --- /dev/null +++ b/test/parallel/test-http-flush-headers.js @@ -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(); +});