[fix] fixed that f..reaking bug

This commit is contained in:
yawnt 2013-07-25 22:22:20 +02:00 committed by cronopio
parent 1a4da5d76e
commit 10c218b804
2 changed files with 13 additions and 5 deletions

Binary file not shown.

View File

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