Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[fix] http-proxy should not modify the protocol in redirect request f…
…or external sites. Fixes #359.
  • Loading branch information
indexzero committed Mar 9, 2013
1 parent 3130665 commit 6a278b3
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions lib/node-http-proxy/http-proxy.js
Expand Up @@ -27,6 +27,7 @@
var events = require('events'),
http = require('http'),
util = require('util'),
url = require('url'),
httpProxy = require('../node-http-proxy');

//
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -257,11 +259,14 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {

if ((response.statusCode === 301) || (response.statusCode === 302)
&& typeof response.headers.location !== 'undefined') {
if (self.source.https && !self.target.https) {
response.headers.location = response.headers.location.replace(/^http\:/, 'https:');
}
if (self.target.https && !self.source.https) {
response.headers.location = response.headers.location.replace(/^https\:/, 'http:');
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:');
}
if (self.target.https && !self.source.https) {
response.headers.location = response.headers.location.replace(/^https\:/, 'http:');
}
}
}

Expand Down

0 comments on commit 6a278b3

Please sign in to comment.