Skip to content

Commit 1a4da5d

Browse files
yawntcronopio
authored andcommitted
[fix] started fixing stuff
1 parent 64b4e07 commit 1a4da5d

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

lib/node-http-proxy/streams/proxy.js

+21-12
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ var Duplex = require('stream').Duplex,
88
var ProxyStream = module.exports = function ProxyStream(response, options) {
99
Duplex.call(this);
1010

11-
var self = this,
12-
target = options.target,
13-
source = options.source;
11+
var self = this,
12+
target = options.target,
13+
source = options.source;
14+
15+
self.origRes = response;
1416

1517
this.once('pipe', function(req) {
1618
var protocol = target.https ? https : http,
@@ -21,8 +23,13 @@ var ProxyStream = module.exports = function ProxyStream(response, options) {
2123
if (options.changeOrigin) {
2224
outgoing.headers.host = target.host + ':' + target.port;
2325
}
24-
25-
self.request = protocol.request(outgoing, function(res) {
26+
27+
self.request = protocol.request(outgoing);
28+
self.request.end();
29+
30+
self.request.on('response', function (res) {
31+
console.log('yarr yarr');
32+
self.response = res;
2633
if(req.httpVersion === '1.0') {
2734
res.headers.connection = req.headers.connection || 'close';
2835
}
@@ -56,7 +63,8 @@ var ProxyStream = module.exports = function ProxyStream(response, options) {
5663
});
5764
response.writeHead(response.statusCode);
5865
});
59-
66+
67+
6068
/*
6169
//
6270
// Handle 'error' events from the `reverseProxy`. Setup timeout override if needed
@@ -110,15 +118,16 @@ var ProxyStream = module.exports = function ProxyStream(response, options) {
110118

111119
};
112120

121+
ProxyStream.prototype = Object.create(
122+
Duplex.prototype, { constructor: { value: ProxyStream } }
123+
);
124+
113125
ProxyStream.prototype._write = function(chunk, encoding, callback) {
114126
this.request.write(chunk, encoding, callback);
115127
};
116128

117129
ProxyStream.prototype._read = function(size) {
118-
var chunk = self.request.read();
119-
if(chunk !== null) {
120-
this.push(chunk);
121-
}
130+
var chunk = this.response ? this.response.read(size) : '';
131+
console.log(chunk.toString());
132+
this.push(chunk);
122133
};
123-
124-
util.inherits(ProxyStream, Duplex);

0 commit comments

Comments
 (0)