[fix] be defensive and ensure location is in headers before running url.parse()

This commit is contained in:
Jarrett Cruger 2014-11-25 17:22:23 -05:00
parent 48ae5d828c
commit 8d68ac0e0f

View File

@ -47,7 +47,9 @@ var redirectRegex = /^30(1|2|7|8)$/;
},
function setRedirectHostRewrite(req, res, proxyRes, options) {
if (options.hostRewrite && redirectRegex.test(proxyRes.statusCode)) {
if (options.hostRewrite
&& proxyRes.headers['location']
&& redirectRegex.test(proxyRes.statusCode)) {
var u = url.parse(proxyRes.headers['location']);
u.host = options.hostRewrite;
proxyRes.headers['location'] = u.format();