diff --git a/lib/node-http-proxy/http-proxy.js b/lib/node-http-proxy/http-proxy.js index 3306defcc..924ef0e23 100644 --- a/lib/node-http-proxy/http-proxy.js +++ b/lib/node-http-proxy/http-proxy.js @@ -235,10 +235,10 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) { } if ((response.statusCode === 301) || (response.statusCode === 302)) { - if (self.source.https && !self.target.https) { + if (self.source.https && !self.target.https && response.headers.location != null) { response.headers.location = response.headers.location.replace(/^http\:/, 'https:'); } - if (self.target.https && !self.source.https) { + if (self.target.https && !self.source.https && response.headers.location != null) { response.headers.location = response.headers.location.replace(/^https\:/, 'http:'); } }