From 1a4da5d76e746209d086ee464552aadc60c4fde8 Mon Sep 17 00:00:00 2001 From: yawnt Date: Thu, 25 Jul 2013 21:19:15 +0200 Subject: [PATCH] [fix] started fixing stuff --- lib/node-http-proxy/streams/proxy.js | 33 ++++++++++++++++++---------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/lib/node-http-proxy/streams/proxy.js b/lib/node-http-proxy/streams/proxy.js index aa5573c..8235e95 100644 --- a/lib/node-http-proxy/streams/proxy.js +++ b/lib/node-http-proxy/streams/proxy.js @@ -8,9 +8,11 @@ var Duplex = require('stream').Duplex, var ProxyStream = module.exports = function ProxyStream(response, options) { Duplex.call(this); - var self = this, - target = options.target, - source = options.source; + var self = this, + target = options.target, + source = options.source; + + self.origRes = response; this.once('pipe', function(req) { var protocol = target.https ? https : http, @@ -21,8 +23,13 @@ var ProxyStream = module.exports = function ProxyStream(response, options) { if (options.changeOrigin) { outgoing.headers.host = target.host + ':' + target.port; } - - self.request = protocol.request(outgoing, function(res) { + + self.request = protocol.request(outgoing); + 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'; } @@ -56,7 +63,8 @@ var ProxyStream = module.exports = function ProxyStream(response, options) { }); response.writeHead(response.statusCode); }); - + + /* // // Handle 'error' events from the `reverseProxy`. Setup timeout override if needed @@ -110,15 +118,16 @@ var ProxyStream = module.exports = function ProxyStream(response, options) { }; +ProxyStream.prototype = Object.create( + Duplex.prototype, { constructor: { value: ProxyStream } } +); + ProxyStream.prototype._write = function(chunk, encoding, callback) { this.request.write(chunk, encoding, callback); }; ProxyStream.prototype._read = function(size) { - var chunk = self.request.read(); - if(chunk !== null) { - this.push(chunk); - } + var chunk = this.response ? this.response.read(size) : ''; + console.log(chunk.toString()); + this.push(chunk); }; - -util.inherits(ProxyStream, Duplex);