diff --git a/lib/node-http-proxy/.http-proxy.js.swp b/lib/node-http-proxy/.http-proxy.js.swp new file mode 100644 index 0000000..f3ed579 Binary files /dev/null and b/lib/node-http-proxy/.http-proxy.js.swp differ diff --git a/lib/node-http-proxy/streams/proxy.js b/lib/node-http-proxy/streams/proxy.js index 8235e95..f8d12bb 100644 --- a/lib/node-http-proxy/streams/proxy.js +++ b/lib/node-http-proxy/streams/proxy.js @@ -11,8 +11,6 @@ var ProxyStream = module.exports = function ProxyStream(response, options) { var self = this, target = options.target, source = options.source; - - self.origRes = response; this.once('pipe', function(req) { var protocol = target.https ? https : http, @@ -25,10 +23,11 @@ var ProxyStream = module.exports = function ProxyStream(response, options) { } self.request = protocol.request(outgoing); - self.request.end(); + self.on('finish', function() { + self.request.end(); + }); self.request.on('response', function (res) { - console.log('yarr yarr'); self.response = res; if(req.httpVersion === '1.0') { res.headers.connection = req.headers.connection || 'close'; @@ -62,6 +61,15 @@ var ProxyStream = module.exports = function ProxyStream(response, options) { response.setHeader(key, res.headers[key]); }); response.writeHead(response.statusCode); + + res.on('readable', function() { + self.read(0); + }); + + res.on('end', function() { + self.push(null); + }); + self.emit('readable'); }); @@ -128,6 +136,6 @@ ProxyStream.prototype._write = function(chunk, encoding, callback) { ProxyStream.prototype._read = function(size) { var chunk = this.response ? this.response.read(size) : ''; - console.log(chunk.toString()); + if(chunk == null) { chunk = '' } this.push(chunk); };