Allow optional redirect host rewriting.

This commit is contained in:
Sam Saccone 2014-11-21 00:19:11 -05:00
parent aba505d159
commit daf66a7a88
2 changed files with 11 additions and 3 deletions

View File

@ -144,7 +144,7 @@ web_o = Object.keys(web_o).map(function(pass) {
proxyReq.on('response', function(proxyRes) { proxyReq.on('response', function(proxyRes) {
if(server) { server.emit('proxyRes', proxyRes, req, res); } if(server) { server.emit('proxyRes', proxyRes, req, res); }
for(var i=0; i < web_o.length; i++) { for(var i=0; i < web_o.length; i++) {
if(web_o[i](req, res, proxyRes)) { break; } if(web_o[i](req, res, proxyRes, options)) { break; }
} }
// Allow us to listen when the proxy has completed // Allow us to listen when the proxy has completed

View File

@ -1,5 +1,6 @@
var url = require('url')
var passes = exports; var passes = exports;
var redirectRegex = /^30(1|2|7|8)$/;
/*! /*!
* Array of passes. * Array of passes.
* *
@ -43,6 +44,13 @@ var passes = exports;
} }
}, },
function setRedirectHostRewrite(req, res, proxyRes, options) {
if (options.hostRewrite && redirectRegex.test(proxyRes.statusCode)) {
var u = url.parse(proxyRes.headers['location']);
u.host = options.hostRewrite;
proxyRes.headers['location'] = u.format();
}
},
/** /**
* Copy headers from proxyResponse to response * Copy headers from proxyResponse to response
* set each header in response object. * set each header in response object.