mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
[fix] started fixing stuff
This commit is contained in:
parent
64b4e07ffb
commit
1a4da5d76e
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user