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

set_proxy prepends value with "http://" regardless of what is passed in #512

Closed
ttilberg opened this issue Dec 8, 2017 · 2 comments
Closed

Comments

@ttilberg
Copy link
Contributor

ttilberg commented Dec 8, 2017

Some services require that when you specify a proxy address, it includes the URI protocol (http), while some libraries handle it for you. To better accommodate abstractions, this is desirable that it adds http when needed -- but only if it's needed.

Mechanize is an example that handles it for you, but does so without checking what was passed in, and can create a hard-to-find error, especially if you don't see the value set_proxy returns.

proxy = { address: "http://127.0.0.1", port: 8080}
agent = Mechanize.new
agent.set_proxy proxy[:address], proxy[:port]
# => #<URI::HTTP http://http:8080//127.0.0.1>

agent.get 'https://api.ipify.org'
SocketError: getaddrinfo: Name or service not known
from /home/ttilberg/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/net/http.rb:879:in `initialize'

When you dig into the source, you come across this note:

  ##
  # Sets the proxy address, port, user, and password +addr+ should be a host,
  # with no "http://", +port+ may be a port number, service name or port
  # number string.

It handles the address with this line.

Is there a reason that proxy_uri = URI "http://#{addr}" couldn't or shouldn't be fleshed out better to check for %r(^https?//)

@scottschup
Copy link

Seems like this issue should be closed now.

@ttilberg
Copy link
Contributor Author

Yes, thank you!

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

2 participants