axsuul / rails-reverse-proxy

A reverse proxy for Ruby on Rails
MIT License
237 stars 59 forks source link

Need a way to specify proxy host and proxy port #33

Open starrychloe opened 5 years ago

starrychloe commented 5 years ago

I'd like to specify Fiddler as a proxy so I can inspect the requests and responses easier. I need to specify localhost:7777 as a proxy. However, this doesn't allow proxy parameters, even though Net::HTTP does. The docs say you can provide a http: {} hash but the options to the linked method are only about certificates. The proxy host and proxy port are given by the 3rd and 4th arguments, and you can't specify them via a hash of options.

https://ruby-doc.org/stdlib-2.4.0/libdoc/net/http/rdoc/Net/HTTP.html#start-method

axvm commented 5 years ago

Implemented proxy support in my fork https://github.com/axvm/rails-reverse-proxy

How to use:

reverse_proxy 'https://google.com', headers: { Host: 'google.com' }, proxy: { host: '127.0.0.1', port: 8888 } do
  # implement here your callbacks
end
semaperepelitsa commented 4 years ago

If you want to use this proxy for the whole app, it might be easier to use "http_proxy" environment variable, since it is automatically picked up by Net::HTTP and other networking libraries.

export http_proxy=localhost:7777