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

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

Open
richardwan opened this issue May 25, 2022 · 2 comments

Comments

@richardwan
Copy link

richardwan commented May 25, 2022

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.

@pduey
Copy link

pduey commented Jul 14, 2023

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.

@axsuul
Copy link
Owner

axsuul commented Jul 14, 2023

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

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

No branches or pull requests

3 participants