Adding CUSTOM headers through the proxy passthrough? X-Forwarded-For? Etc? #508

Open
Analogreality opened this Issue Nov 2, 2013 · 5 comments

Projects

None yet

4 participants

I need to be able to pass custom HTTP headers to the HTTP server behind this proxy.

For example, look at this guy:
http://blog.nikmartin.com/2013/07/secure-sessions-in-nodejs-with-nginx.html

He adds a few headers to indicate to the receiving server that it is a passthrough, with the real IP address.

How can I do the same with node-http-proxy?

I would assume the proxy should create a X-Forwarded-For header automaticaly (does it).. but additionally add other headers I specify.

What is the best way of doing this?

I am looking at the main beef of the code here:
https://github.com/nodejitsu/node-http-proxy/blob/master/lib/node-http-proxy/http-proxy.js

There are some juicy parts where I can hook up event listeners.. but I would like to know the BEST usage for them.. I am trying to find explicit documentation on them.

Contributor
cronopio commented Nov 4, 2013

Hi @Analogreality We're working in a total refactor to support node v0.10.x at the caronte branch please take a look of the new way of hook up your own logic, we called "passes", by now there is a xfwd option that you can set to true to set the x-forward-* headers here, also you can set your own "pass" and make what you want before pipe the request/response.

Hope this help, I'll keep this open until you resolve your doubt

cheddar commented Feb 11, 2014

@cronopio I'm trying to do something similar (specifically, I want to be able to add CORS headers on the outgoing responses) and I see the passes, but I'm not seeing the proper method to use to add things to the passes?

I'd like to add it after web-outgoing.writeHeaders and before web-outgoing.writeStatusCode. Is there any example available somewhere that shows how to do that?

cheddar commented Feb 11, 2014

Fwiw, I just did a pull request to try to enable this.

#582

ericfong commented Jul 1, 2015

How about "x-forwarded-host" ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment