Skip to content

Commit 74782bd

Browse files
committed
Allow optional redirect host rewriting.
1 parent aba505d commit 74782bd

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/http-proxy/passes/web-incoming.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ web_o = Object.keys(web_o).map(function(pass) {
144144
proxyReq.on('response', function(proxyRes) {
145145
if(server) { server.emit('proxyRes', proxyRes, req, res); }
146146
for(var i=0; i < web_o.length; i++) {
147-
if(web_o[i](req, res, proxyRes)) { break; }
147+
if(web_o[i](req, res, proxyRes, options)) { break; }
148148
}
149149

150150
// Allow us to listen when the proxy has completed

lib/http-proxy/passes/web-outgoing.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var url = require('url')
12
var passes = exports;
23

34
/*!
@@ -43,6 +44,13 @@ var passes = exports;
4344
}
4445
},
4546

47+
function setRedirectHostRewrite(req, res, proxyRes, options) {
48+
if (options.hostRewrite && /^30(1|2|7|8)$/.test(proxyRes.statusCode)) {
49+
var u = url.parse(proxyRes.headers['location']);
50+
u.host = options.hostRewrite;
51+
proxyRes.headers['location'] = u.format();
52+
}
53+
},
4654
/**
4755
* Copy headers from proxyResponse to response
4856
* set each header in response object.

0 commit comments

Comments
 (0)