Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix bug where http response.readable was never set to false

  • Loading branch information...
commit 5e576f32ef6314b30b789d7c1d4dc8cfd78a5453 1 parent 75db199
@abram abram authored
Showing with 61 additions and 0 deletions.
  1. +1 −0  lib/http.js
  2. +60 −0 test/simple/test-http-client-pipe.js
View
1  lib/http.js
@@ -1305,6 +1305,7 @@ Agent.prototype._establishNewConnection = function() {
res.addListener('end', function() {
debug('AGENT request complete');
+ res.readable = false;
// For the moment we reconnect for every request. FIXME!
// All that should be required for keep-alive is to not reconnect,
// but outgoingFlush instead.
View
60 test/simple/test-http-client-pipe.js
@@ -0,0 +1,60 @@
+var common = require('../common');
+var assert = require('assert');
+var http = require('http');
+var stream = require('stream');
+var util = require('util');
+
+function SlowStream() {
+ stream.Stream.call(this);
+ this.writable = true;
+ this.output = '';
+}
+util.inherits(SlowStream, stream.Stream);
+
+SlowStream.prototype.write = function(buffer) {
+ this.output += buffer.toString();
+ console.log('wrote data.');
+ var self = this;
+ this.emit('pause');
+ setTimeout(function() {
+ self.emit('drain');
+ }, 100);
+};
+
+SlowStream.prototype.end = function() {
+ testServer.close();
+};
+
+var chunks = ['hello ', 'world'];
+
+var testServer = new http.Server(function(req, res) {
+ res.writeHead(200);
+ res.write(chunks[0]);
+ process.nextTick(function() {
+ res.write(chunks[1]);
+ process.nextTick(function() {
+ res.end();
+ });
+ });
+});
+
+testServer.listen(common.PORT);
+
+var outputStream = new SlowStream();
+
+var request = http.get({
+ host: 'localhost',
+ port: common.PORT,
+ path: '/',
+}, function(response) {
+ response.on('data', function() { console.log('got some data'); });
+ // If response.readable isn't being properly set to false, this will
+ // cause an error, because the final time .resume() is called on the
+ // response the underlying socket will already be closed.
+ response.pipe(outputStream);
+});
+request.end();
+
+process.addListener('exit', function() {
+ assert.equal(outputStream.output, chunks.join(''));
+});
Please sign in to comment.
Something went wrong with that request. Please try again.