Skip to content

Commit

Permalink
[fix] started fixing stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
yawnt committed Jul 25, 2013
1 parent 0e297ac commit 4a6da2c
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions lib/node-http-proxy/streams/proxy.js
Expand Up @@ -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,
Expand All @@ -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';
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);

0 comments on commit 4a6da2c

Please sign in to comment.