mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
Allow optional redirect host rewriting.
This commit is contained in:
parent
aba505d159
commit
daf66a7a88
@ -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
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
var passes = exports;
|
var url = require('url')
|
||||||
|
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.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user