-
Notifications
You must be signed in to change notification settings - Fork 8
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
Allow to send proxy params. #27
base: master
Are you sure you want to change the base?
Allow to send proxy params. #27
Conversation
@ryanfox1985 Thank you for the pull request. Is there a reason you're unable to use the |
@gaffneyc is not possible to use the http_proxy because right now is not calling with the good parameters to the method start. Here you have the link to the documentation https://www.rubydoc.info/stdlib/net/Net%2FHTTP.start to review. The propose of this PR is resolve this issue with the parameters. |
the current code is overriding the p_addr => And removes the default value :ENV |
My proposal fixes the parameters order and allows more flexibility to configure the proxy passing options. |
Trying to find documentation for it but I believe Ruby will automatically use the |
@ryanfox1985 Here is the documentation https://ruby-doc.org/stdlib-2.7.1/libdoc/net/http/rdoc/Net/HTTP.html#class-Net::HTTP-label-Proxies It seems like you should be able to do this to use a proxy:
|
@gaffneyc not working your proposal with the current code: Net::HTTP.start(uri.host, uri.port, opts) do |http|
...
opts = hash { with timeouts... } The current code overrides the parameter p_addr (with a default value :ENV) for opts that is a hash and its the 7th parameter, look the api doc for HTTP.start(address, port=nil, p_addr=:ENV, p_port=nil, p_user=nil, p_pass=nil, opt, &block) |
The current code sends |
@ryanfox1985 The signature for At least in this case, the call to The question I have: for your use case do you need to pass in the proxy params? def HTTP.start(address, *arg, &block)
arg.pop if opt = Hash.try_convert(arg[-1])
port, p_addr, p_port, p_user, p_pass = *arg
p_addr = :ENV if arg.size < 2
port = https_default_port if !port && opt && opt[:use_ssl]
http = new(address, port, p_addr, p_port, p_user, p_pass)
http.ipaddr = opt[:ipaddr] if opt && opt[:ipaddr]
if opt
if opt[:use_ssl]
opt = {verify_mode: OpenSSL::SSL::VERIFY_PEER}.update(opt)
end
http.methods.grep(/\A(\w+)=\z/) do |meth|
key = $1.to_sym
opt.key?(key) or next
http.__send__(meth, opt[key])
end
end
http.start(&block)
end |
@ryanfox1985 I mentioned the Using tinyproxy I was able to set up a local HTTP proxy that logged requests. (Using I then ran the below code to test that http_proxy=http://127.0.0.1:8888 DMS_API_KEY=[key here] ruby examples/api.rb I was then able to see in the tinyproxy logs that it was connecting through the proxy
|
@gaffneyc I reviewed the source and you are right. The first line removes the last argument if it's a hash: Finally I discovered my problem, we have ruby 2.1.3 and the net library not sets p_addr, leaves as a Here you can check the source => https://apidock.com/ruby/v2_1_10/Net/HTTP/start/class |
@ryanfox1985 Hm... okay. Ruby 2.1 is really old at this point. Are you using Snitcher inside an application or from the command line with the system default ruby? |
Found the feature request for http_proxy support and it looks like it should work for Ruby 2.0 and newer. I will see if I can test it against Ruby 2.1. |
After some more testing it looks like the |
lib/snitcher.rb
Outdated
use_ssl: use_ssl?(uri), | ||
} | ||
[ | ||
options.fetch(:p_addr, :ENV), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My PR starts to have sense for ruby < 2.5
Maybe I can detect the ruby version here and sets:
- nil for Ruby < 2.5
- :ENV for Ruby >= 2.5
…nto feature/send_proxy_params
Hello,
according with this documentation:
https://www.rubydoc.info/stdlib/net/Net%2FHTTP.start
The opts parameters are not send in a correct order, also is not allowed to request though a proxy.
Regards.