rails-reverse-proxy icon indicating copy to clipboard operation
rails-reverse-proxy copied to clipboard

feature request: default headers to match proxy url for host and request headers for accept

Open richardwan opened this issue 2 years ago • 2 comments

in order to successfully proxy, i had to do a workaround

    headers = {
      'Host' => host,
      'Accept' => request.headers.to_h['HTTP_ACCEPT'] 
    }
    reverse_proxy "https://#{host}", headers: headers

instead of reverse_proxy "https://#{host}"

is there any appetite for either making the workaround the default behavior in the gem or an option that the gem recognizes to do this? If so, I can make a fork and submit a PR.

richardwan avatar May 25 '22 14:05 richardwan

The 'Host' header and the "host" arg (1st param in call to reverse_proxy) are two different things. But I agree, this gem should add it if the caller did not set it. E.g., in client.rb:

      # Define headers
      target_request_headers = extract_http_request_headers(source_request.env).merge(options[:headers])
+     target_request_headers["Host"] ||= URI.parse(uri).host

Scenario: When running 2 "pure" rails (i.e., Puma or whatever web server you bundle in development) apps, you can reverse proxy from one to the other. But when you add another web server like nginx (typical in a production-like environment), it does not work without the "Host" header.

If the repo owner agrees, I can create a PR.

pduey avatar Jul 14 '23 16:07 pduey

Sure that sounds great, PR welcome 😊 Also please add a comment with this context

axsuul avatar Jul 14 '23 16:07 axsuul