http: add flushHeaders and deprecate flush
authorYosuke Furukawa <yosuke.furukawa@gmail.com>
Sat, 14 Mar 2015 07:24:07 +0000 (16:24 +0900)
committerBen Noordhuis <info@bnoordhuis.nl>
Mon, 16 Mar 2015 23:54:11 +0000 (00:54 +0100)
PR-URL: https://github.com/iojs/io.js/pull/1156
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Christian Tellnes <christian@tellnes.no>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
doc/api/http.markdown
lib/_http_outgoing.js
test/parallel/test-http-flush-headers.js [new file with mode: 0644]

index c4af8f4..de8e7eb 100644 (file)
@@ -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])
index f6144ba..3102261 100644 (file)
@@ -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 (file)
index 0000000..ede0fa5
--- /dev/null
@@ -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();
+});