Skip to content

Commit

Permalink
[fix] fixed that f..reaking bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yawnt committed Jul 25, 2013
1 parent 4a6da2c commit 9fa91b4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Binary file added lib/node-http-proxy/.http-proxy.js.swp
Binary file not shown.
18 changes: 13 additions & 5 deletions lib/node-http-proxy/streams/proxy.js
Expand Up @@ -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,
Expand All @@ -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';
Expand Down Expand Up @@ -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');
});


Expand Down Expand Up @@ -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);
};

3 comments on commit 9fa91b4

@cronopio
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yawnt Thank you man, with this commit most of basic http tests now pass, but Im having troubles in forward case, when use the forward stream. I think that is incomplete by now, I think you are focusing first on this stream, now the question is this stuff kind of finished? can I try to mess with the forward stream adding this new listeners, etc?? I'll be online at IRC to further discuss.

@cronopio
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in other words, we can hack together to finish this and the forward stream. :-)

@yawnt
Copy link
Contributor Author

@yawnt yawnt commented on 9fa91b4 Jul 26, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ya i focused on proxystream first.. im at the sea right now, so connection sucks .. when will you be online? so we can catch up

Please sign in to comment.