Skip to content

Commit 6a278b3

Browse files
committed
[fix] http-proxy should not modify the protocol in redirect request for external sites. Fixes #359.
1 parent 3130665 commit 6a278b3

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

Diff for: lib/node-http-proxy/http-proxy.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
var events = require('events'),
2828
http = require('http'),
2929
util = require('util'),
30+
url = require('url'),
3031
httpProxy = require('../node-http-proxy');
3132

3233
//
@@ -122,7 +123,8 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
122123
var self = this,
123124
errState = false,
124125
outgoing = new(this.target.base),
125-
reverseProxy;
126+
reverseProxy,
127+
location;
126128

127129
//
128130
// Add common proxy headers to the request so that they can
@@ -257,11 +259,14 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
257259

258260
if ((response.statusCode === 301) || (response.statusCode === 302)
259261
&& typeof response.headers.location !== 'undefined') {
260-
if (self.source.https && !self.target.https) {
261-
response.headers.location = response.headers.location.replace(/^http\:/, 'https:');
262-
}
263-
if (self.target.https && !self.source.https) {
264-
response.headers.location = response.headers.location.replace(/^https\:/, 'http:');
262+
location = url.parse(response.headers.location);
263+
if (location.host === req.headers.host) {
264+
if (self.source.https && !self.target.https) {
265+
response.headers.location = response.headers.location.replace(/^http\:/, 'https:');
266+
}
267+
if (self.target.https && !self.source.https) {
268+
response.headers.location = response.headers.location.replace(/^https\:/, 'http:');
269+
}
265270
}
266271
}
267272

0 commit comments

Comments
 (0)