Skip to content
Permalink
Browse files

[fix] started fixing stuff

  • Loading branch information...
yawnt committed Jul 25, 2013
1 parent 0e297ac commit 4a6da2ce937e21d0ebdca9d1054277880f37df3c
Showing with 21 additions and 12 deletions.
  1. +21 −12 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);

0 comments on commit 4a6da2c

Please sign in to comment.
You can’t perform that action at this time.