mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
[fix] http-proxy should not modify the protocol in redirect request for external sites. Fixes #359.
This commit is contained in:
parent
3130665d9f
commit
6a278b3dd8
@ -27,6 +27,7 @@
|
|||||||
var events = require('events'),
|
var events = require('events'),
|
||||||
http = require('http'),
|
http = require('http'),
|
||||||
util = require('util'),
|
util = require('util'),
|
||||||
|
url = require('url'),
|
||||||
httpProxy = require('../node-http-proxy');
|
httpProxy = require('../node-http-proxy');
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -122,7 +123,8 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
|
|||||||
var self = this,
|
var self = this,
|
||||||
errState = false,
|
errState = false,
|
||||||
outgoing = new(this.target.base),
|
outgoing = new(this.target.base),
|
||||||
reverseProxy;
|
reverseProxy,
|
||||||
|
location;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Add common proxy headers to the request so that they can
|
// Add common proxy headers to the request so that they can
|
||||||
@ -257,11 +259,14 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
|
|||||||
|
|
||||||
if ((response.statusCode === 301) || (response.statusCode === 302)
|
if ((response.statusCode === 301) || (response.statusCode === 302)
|
||||||
&& typeof response.headers.location !== 'undefined') {
|
&& typeof response.headers.location !== 'undefined') {
|
||||||
if (self.source.https && !self.target.https) {
|
location = url.parse(response.headers.location);
|
||||||
response.headers.location = response.headers.location.replace(/^http\:/, 'https:');
|
if (location.host === req.headers.host) {
|
||||||
}
|
if (self.source.https && !self.target.https) {
|
||||||
if (self.target.https && !self.source.https) {
|
response.headers.location = response.headers.location.replace(/^http\:/, 'https:');
|
||||||
response.headers.location = response.headers.location.replace(/^https\:/, 'http:');
|
}
|
||||||
|
if (self.target.https && !self.source.https) {
|
||||||
|
response.headers.location = response.headers.location.replace(/^https\:/, 'http:');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user