mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
[fix] ProxyStraem now works
This commit is contained in:
parent
d4f0da898e
commit
356f43d719
@ -28,7 +28,6 @@ ProxyStream.prototype.onPipe = function(req) {
|
||||
);
|
||||
//console.log(common.setupOutgoing(self.options.ssl || {}, self.options, req));
|
||||
this.proxyReq.once('response', function(proxyRes) {
|
||||
console.log(proxyRes);
|
||||
self.onResponse(proxyRes);
|
||||
});
|
||||
this.proxyReq.on('error', function(e) {
|
||||
@ -43,46 +42,47 @@ ProxyStream.prototype.onFinish = function() {
|
||||
ProxyStream.prototype.onResponse = function(proxyRes) {
|
||||
this.proxyRes = proxyRes;
|
||||
|
||||
// rewrite
|
||||
if(req.httpVersion === '1.0') {
|
||||
res.headers.connection = req.headers.connection || 'close';
|
||||
}
|
||||
else if(!res.headers.connection) {
|
||||
res.headers.connection = req.headers.connection || 'keep-alive';
|
||||
}
|
||||
var self = this;
|
||||
|
||||
if(req.httpVersion === '1.0' || (req.method === 'DELETE' && !req.headers['content-length'])) {
|
||||
delete res.headers['transfer-encoding'];
|
||||
}
|
||||
if(this.req.httpVersion === '1.0') {
|
||||
proxyRes.headers.connection = this.req.headers.connection || 'close';
|
||||
}
|
||||
else if(!proxyRes.headers.connection) {
|
||||
proxyRes.headers.connection = this.req.headers.connection || 'keep-alive';
|
||||
}
|
||||
|
||||
if(~[301,302].indexOf(res.statusCode) && typeof res.headers.location !== 'undefined') {
|
||||
var location = url.parse(res.headers.location);
|
||||
if (
|
||||
location.host === req.headers.host &&
|
||||
(
|
||||
source.https && !target.https ||
|
||||
target.https && !source.https
|
||||
)
|
||||
) {
|
||||
res.headers.location = res.headers.location.replace(/^https\:/, 'http:');
|
||||
}
|
||||
}
|
||||
if(this.req.httpVersion === '1.0' || (this.req.method === 'DELETE' && !this.req.headers['content-length'])) {
|
||||
delete proxyRes.headers['transfer-encoding'];
|
||||
}
|
||||
|
||||
self.emit('proxyResponse', req, response, res);
|
||||
/*if(~[301,302].indexOf(this.res.statusCode) && typeof this.res.headers.location !== 'undefined') {
|
||||
var location = url.parse(this.res.headers.location);
|
||||
if (
|
||||
location.host === this.req.headers.host &&
|
||||
(
|
||||
source.https && !target.https ||
|
||||
target.https && !source.https
|
||||
)
|
||||
) {
|
||||
this.res.headers.location = this.res.headers.location.replace(/^https\:/, 'http:');
|
||||
}
|
||||
}*/
|
||||
|
||||
Object.keys(res.headers).forEach(function (key) {
|
||||
response.setHeader(key, res.headers[key]);
|
||||
});
|
||||
response.writeHead(response.statusCode);
|
||||
|
||||
res.on('readable', function() {
|
||||
self.read(0);
|
||||
});
|
||||
Object.keys(proxyRes.headers).forEach(function (key) {
|
||||
self.res.setHeader(key, proxyRes.headers[key]);
|
||||
});
|
||||
|
||||
res.on('end', function() {
|
||||
self.push(null);
|
||||
});
|
||||
self.emit('readable');
|
||||
this.res.writeHead(proxyRes.statusCode);
|
||||
|
||||
proxyRes.on('readable', function() {
|
||||
self.read(0);
|
||||
});
|
||||
|
||||
proxyRes.on('end', function() {
|
||||
self.push(null);
|
||||
});
|
||||
|
||||
self.emit('readable');
|
||||
};
|
||||
|
||||
ProxyStream.prototype.onError = function(e) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user