Permalink
Browse files

[fix] http-proxy should not modify the protocol in redirect request f…

…or external sites. Fixes #359.
  • Loading branch information...
1 parent 3130665 commit 6a278b3dd88d3b786cdaa9dec4c6011119e05a59 @indexzero indexzero committed Mar 9, 2013
Showing with 11 additions and 6 deletions.
  1. +11 −6 lib/node-http-proxy/http-proxy.js
View
17 lib/node-http-proxy/http-proxy.js
@@ -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,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:');
+ }
}
}

0 comments on commit 6a278b3

Please sign in to comment.