Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Closed
wants to merge 1 commit into from

3 participants

@bunnyyiu

In some cases, the target site may redirect the request to external url
which is not our proxying target. It is better not to modify the
protocol in this case.

@bunnyyiu bunnyyiu [fix] Http-proxy should not modify protocol that not under target host.
In some cases, the target site may redirect the request to external url
which is not our proxying target. It is better not to modify the
protocol in this case.
147eb91
@indexzero indexzero closed this in 6a278b3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 3, 2013
  1. @bunnyyiu

    [fix] Http-proxy should not modify protocol that not under target host.

    bunnyyiu authored
    In some cases, the target site may redirect the request to external url
    which is not our proxying target. It is better not to modify the
    protocol in this case.
This page is out of date. Refresh to see the latest.
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');
//
@@ -228,7 +229,7 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
if (this.changeOrigin) {
outgoing.headers.host = this.target.host + ':' + this.target.port;
}
-
+
//
// Open new HTTP request to internal resource with will act
// as a reverse proxy pass
@@ -248,11 +249,15 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
}
if ((response.statusCode === 301) || (response.statusCode === 302)) {
- 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:');
+ // Only change protocol if url under target host
+ var parsedLocation = url.parse(response.headers.location);
+ if (parsedLocation.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:');
+ }
}
}
Something went wrong with that request. Please try again.