Skip to content

Fixed the usage of passing proxy setting to open-uri module. #566

Merged
merged 1 commit into from Feb 19, 2014

3 participants

@TonnyXu
TonnyXu commented Feb 18, 2014

The old way, using the :proxy parameter does not work in a proxy environment. Set the proxy options works. This also works for proxy without authentication.

tonny.xu Fixed the usage of passing proxy setting to open-uri module. Using the
options can make sure it works. The old way, using the :proxy parameter
does not work in a proxy environment.
5596bb0
@kalbasit
carlhuda member

LGTM

@kalbasit kalbasit merged commit 39c7bcb into carlhuda:master Feb 19, 2014
@silent-e

This is breaking in my non-proxy ENV since the proxy variable will receive nil and URI.parse blows up with nil. I'm using 2.0.0-p353. I fixed it quickly with ...

  def download_and_save_file(url, path)
    open_and_save_file(path, open(url, options_for_open).read)
  end

  # Setup proxy options if needed
  #
  def options_for_open
    proxy = ENV['http_proxy'] || ENV['HTTP_PROXY']
    return {} if proxy.nil?

    uri = URI.parse(proxy)
    proxy_host = uri.scheme + "://" + uri.host + ":" + uri.port.to_s
    proxy_user, proxy_pass = uri.userinfo.split(/:/) if uri.userinfo
    options = { :proxy_http_basic_authentication => [proxy_host,proxy_user,proxy_pass] }
  end

I'm not able to submit a pull request at this time but I wanted to mention it.

(e)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.