Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow optional redirect host rewriting. #741

Merged
merged 2 commits into from
Nov 25, 2014

Conversation

samccone
Copy link
Contributor

Hey all, really appreciate this great lib, here is a solution I implemented for host rewriting for redirects.

If you are interested in this I can add tests and docs. thanks again

@samccone
Copy link
Contributor Author

related:
#318
#376
#519

@samccone samccone force-pushed the sjs/redirect-host-rewrite branch 2 times, most recently from 727cced to 74782bd Compare November 21, 2014 05:23
@@ -144,7 +144,7 @@ web_o = Object.keys(web_o).map(function(pass) {
proxyReq.on('response', function(proxyRes) {
if(server) { server.emit('proxyRes', proxyRes, req, res); }
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; }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

passing options down to web-outgoing gives us a level on configuration that is nice(/needed) for this kinda stuff :)

@jcrugzz
Copy link
Contributor

jcrugzz commented Nov 21, 2014

@samccone this looks good! Could you add a test for this and update the docs related to this option? Thanks for the contribution!

@samccone
Copy link
Contributor Author

awww snap sweet, I was also thinking about options.hostRewrite being a polymorphic argument and supporting a fn signature to allow for a more complex redirect logic flow (for some people this will be needed)

But I will save that work for another PR.

@samccone
Copy link
Contributor Author

hey @jcrugzz specs and docs are all added.

thanks again for your time, and work on this handy lib.

@samccone samccone force-pushed the sjs/redirect-host-rewrite branch 2 times, most recently from a1fc98e to d1da981 Compare November 23, 2014 18:34
@jcrugzz
Copy link
Contributor

jcrugzz commented Nov 23, 2014

@samccone looks great. I forgot the only one nit here that I will post on the code. Will merge once thats done. Thanks!

@@ -43,6 +44,13 @@ var passes = exports;
}
},

function setRedirectHostRewrite(req, res, proxyRes, options) {
if (options.hostRewrite && /^30(1|2|7|8)$/.test(proxyRes.statusCode)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just precompile the regex at the top? (minor perf thing) Forgot to mention it before

@samccone
Copy link
Contributor Author

all updated @jcrugzz 🎋

@samccone
Copy link
Contributor Author

Hey @jcrugzz was there anything else you needed from me?

@jcrugzz
Copy link
Contributor

jcrugzz commented Nov 25, 2014

@samccone sorry got caught up with things so I didn't get to it. LGTM. Ill post back here with some style nits that I make for next time :). Thanks!

Im also curious about the use of a context function as i dont see it anywhere in the mocha docs.

jcrugzz added a commit that referenced this pull request Nov 25, 2014
Allow optional redirect host rewriting.
@jcrugzz jcrugzz merged commit 95a5887 into http-party:master Nov 25, 2014
@samccone samccone deleted the sjs/redirect-host-rewrite branch November 25, 2014 23:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants