[fix] http-proxy should not modify the protocol in redirect request for external sites. Fixes #359.

This commit is contained in:
indexzero 2013-03-09 02:35:50 -05:00
parent 3130665d9f
commit 6a278b3dd8

View File

@ -27,6 +27,7 @@
var events = require('events'),
http = require('http'),
util = require('util'),
url = require('url'),
httpProxy = require('../node-http-proxy');
//
@ -122,7 +123,8 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
var self = this,
errState = false,
outgoing = new(this.target.base),
reverseProxy;
reverseProxy,
location;
//
// Add common proxy headers to the request so that they can
@ -257,6 +259,8 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
if ((response.statusCode === 301) || (response.statusCode === 302)
&& typeof response.headers.location !== 'undefined') {
location = url.parse(response.headers.location);
if (location.host === req.headers.host) {
if (self.source.https && !self.target.https) {
response.headers.location = response.headers.location.replace(/^http\:/, 'https:');
}
@ -264,6 +268,7 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
response.headers.location = response.headers.location.replace(/^https\:/, 'http:');
}
}
}
//
// When the `reverseProxy` `response` ends, end the