ncr / rack-proxy

A request/response rewriting HTTP proxy. A Rack app.
MIT License
269 stars 94 forks source link

Rack Proxy Behind Another Proxy #14

Closed paulie4 closed 11 years ago

paulie4 commented 11 years ago

I'm using https://github.com/layervault/divergence, which uses rack-proxy. I have an Apache proxy in front of the rack-proxy to provide an HTTPS layer. Unfortunately, Ruby Rack's Rack::Request is getting its host and port values (which rack-proxy uses for its Net::HTTP connection) from env["HTTP_X_FORWARDED_HOST"] instead of from env["HTTP_HOST"](Divergence is expecting rack-proxy to send the request to env["HTTP_HOST"]), so the request gets sent to the wrong place. I'm not sure if this is an error in rack-proxy or in Divergence.

The workaround I did was to first delete the "HTTP_X_FORWARDED_HOST" key from env before Divergence calls rack-proxy's perform_request(), but I'm not sure if that is the best way to fix this. What do you guys think?

paulie4 commented 11 years ago

That was not the right way to fix it, since the base application needs to know the HTTP_X_FORWARDED_HOST value to properly create links. Instead of deleting that env key, I edited rack-proxy-0.3.7/lib/rack/proxy.rb so target_response = HttpStreamingResponse.new() has this host value: env["HTTP_HOST"].split(/:/)[0] and has this port value: env["HTTP_HOST"].split(/:/)[1] ? env["HTTP_HOST"].split(/:/)[1].to_i : 80

ismell commented 11 years ago

I think there needs to be a way to specify the backend when the proxy is constructed.

ncr commented 11 years ago

Just merged #15 which helps with this issue.