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

Implementing noproxy option #642

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

doccaz
Copy link

@doccaz doccaz commented Dec 3, 2019

This implements support for libcurl's "noproxy" option, as described by issue #528.

lib/typhoeus/adapters/faraday.rb Outdated Show resolved Hide resolved
@doccaz
Copy link
Author

doccaz commented Dec 4, 2019

Testing the noproxy option...

irb(main):001:0> require 'typhoeus'
=> true

First, we define proxy and noproxy:

irb(main):002:0> Typhoeus::Config.proxy = 'http://localhost:40080'
=> "http://localhost:40080"
irb(main):003:0> Typhoeus::Config.noproxy = 'localhost,.bb.com.br'                      
=> "localhost,.bb.com.br"

Try to fetch an external site:

irb(main):004:0> request = Typhoeus::Request.new("https://www.google.com")
=> #<Typhoeus::Request:0x000056299de4a328 @base_url="https://www.google.com", @original_options={}, @options={:headers=>{"User-Agent"=>"Typhoeus - https://github.com/typhoeus/typhoeus", "Expect"=>""}, :maxredirs=>50, :proxy=>"http://localhost:40080", :noproxy=>"localhost,.bb.com.br"}>

irb(main):005:0> response = request.run
=> #<Typhoeus::Response:0x000056299de50b60 @options={:httpauth_avail=>0, :total_time=>0.023917, :starttransfer_time=>0.0, :appconnect_time=>0.0, :pretransfer_time=>0.0, :connect_time=>0.004332, :namelookup_time=>0.004135, :redirect_time=>0.0, :effective_url=>"https://www.google.com/", :primary_ip=>"127.0.0.1", :response_code=>0, :request_size=>95, :redirect_count=>0, :return_code=>:recv_error, :response_headers=>"**HTTP/1.1 407 Proxy Authentication Required**\r\nServer: squid/3.5.20\r\nMime-Version: 1.0\r\nDate: Wed, 04 Dec 2019 18:53:22 GMT\r\nContent-Type: text/html;charset=utf-8\r\nContent-Length: 3231\r\nX-Squid-Error: ERR_CACHE_ACCESS_DENIED 0\r\nProxy-Authenticate: Basic realm=\"**** 
...

Try to fetch an internal site:

irb(main):006:0> request = Typhoeus::Request.new("http://pkgserver.desenv.bb.com.br")
=> #<Typhoeus::Request:0x000056299de7c670 @base_url="http://pkgserver.desenv.bb.com.br", @original_options={}, @options={:headers=>{"User-Agent"=>"Typhoeus - https://github.com/typhoeus/typhoeus", "Expect"=>""}, :maxredirs=>50, :proxy=>"http://localhost:40080", :noproxy=>"localhost,.bb.com.br"}>

irb(main):007:0> response = request.run
=> #<Typhoeus::Response:0x000056299de84168 @options={:httpauth_avail=>0, :total_time=>0.021907, :starttransfer_time=>0.021757, :appconnect_time=>0.0, :pretransfer_time=>0.013531, :connect_time=>0.01343, :namelookup_time=>0.004184, :redirect_time=>0.0, :effective_url=>"http://pkgserver.desenv.bb.com.br/", :primary_ip=>"172.17.219.9", :response_code=>200, :request_size=>126, :redirect_count=>0, :return_code=>:ok, :response_headers=>"HTTP/1.1 200 OK\r\nDate: Wed, 04 Dec 2019 18:54:09 GMT\r\nServer: Apache\r\nTransfer-Encoding: chunked\r\nContent-Type: text/html;charset=ISO-8859-1\r\n\r\n", :response_body=>"
...

Then we undefine noproxy:

irb(main):009:0> Typhoeus::Config.noproxy = ''                            
=> ""

We try to fetch the internal site again:

irb(main):011:0> request = Typhoeus::Request.new("http://pkgserver.desenv.bb.com.br")
=> #<Typhoeus::Request:0x000056299de87f70 @base_url="http://pkgserver.desenv.bb.com.br", @original_options={}, @options={:headers=>{"User-Agent"=>"Typhoeus - https://github.com/typhoeus/typhoeus", "Expect"=>""}, :maxredirs=>50, :proxy=>"http://localhost:40080", :noproxy=>""}>

irb(main):012:0> response = request.run
=> #<Typhoeus::Response:0x000056299de7ef38 @options={:httpauth_avail=>0, :total_time=>0.032104, :starttransfer_time=>0.031677, :appconnect_time=>0.0, :pretransfer_time=>0.005381, :connect_time=>0.00518, :namelookup_time=>0.004579, :redirect_time=>0.0, :effective_url=>"http://pkgserver.desenv.bb.com.br/", :primary_ip=>"127.0.0.1", :response_code=>200, :request_size=>189, :redirect_count=>0, :return_code=>:ok, :response_headers=>"HTTP/1.1 200 OK\r\nDate: Wed, 04 Dec 2019 18:58:50 GMT\r\nServer: Apache\r\nContent-Type: text/html;charset=ISO-8859-1\r\n**X-Cache: MISS from pxl0squid107**\r\nX-Cache-Lookup: MISS from pxl0squid107:4001\r\nTransfer-Encoding: chunked\r\nVia: 1.1 pxl0squid107 (squid/3.5.20)\r\nConnection: keep-alive\r\n\r\n", :response_body=>"
...

... and it goes through the proxy again.

We define noproxy again:

irb(main):015:0> Typhoeus::Config.noproxy = 'localhost,.bb.com.br'
=> "localhost,.bb.com.br"

irb(main):016:0> request = Typhoeus::Request.new("http://pkgserver.desenv.bb.com.br")
=> #<Typhoeus::Request:0x000056299de36bc0 @base_url="http://pkgserver.desenv.bb.com.br", @original_options={}, @options={:headers=>{"User-Agent"=>"Typhoeus - https://github.com/typhoeus/typhoeus", "Expect"=>""}, :maxredirs=>50, :proxy=>"http://localhost:40080", :noproxy=>"localhost,.bb.com.br"}>

irb(main):017:0> response = request.run
=> #<Typhoeus::Response:0x000056299de31c88 @options={:httpauth_avail=>0, :total_time=>0.01972, :starttransfer_time=>0.019556, :appconnect_time=>0.0, :pretransfer_time=>0.013452, :connect_time=>0.013362, :namelookup_time=>0.004135, :redirect_time=>0.0, :effective_url=>"http://pkgserver.desenv.bb.com.br/", :primary_ip=>"172.17.219.9", :response_code=>200, :request_size=>126, :redirect_count=>0, :return_code=>:ok, :response_headers=>"HTTP/1.1 200 OK\r\nDate: Wed, 04 Dec 2019 18:59:20 GMT\r\nServer: Apache\r\nTransfer-Encoding: chunked\r\nContent-Type: text/html;charset=ISO-8859-1\r\n\r\n", :response_body=>"
...

And it goes through directly as expected.

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

Successfully merging this pull request may close these issues.

None yet

2 participants