In http.Agent, response.readable is never set to false, causing bugs in response.pipe() #867

Closed
wants to merge 4 commits into
from
View
1 lib/http.js
@@ -1311,6 +1311,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
24 test/simple/test-http-response-readable.js
@@ -0,0 +1,24 @@
+var common = require('../common');
+var assert = require('assert');
+var http = require('http');
+
+var testServer = new http.Server(function(req, res) {
+ res.writeHead(200);
+ res.write('Hello world');
+ res.end();
+});
+
+testServer.listen(common.PORT);
+
+var request = http.get({
+ host: 'localhost',
+ port: common.PORT,
+ path: '/',
+}, function(response) {
+ assert.equal(response.readable, true, 'response.readable initially true');
+ response.on('end', function() {
+ assert.equal(response.readable, false,
+ 'response.readable set to false after end');
+ testServer.close();
+ });
+});