module HTTPX::Plugins::Proxy::InstanceMethods

  1. lib/httpx/plugins/proxy.rb

Methods

Public Instance

  1. find_connection

Public Instance methods

find_connection(request_uri, selector, options)
[show source]
    # File lib/httpx/plugins/proxy.rb
157 def find_connection(request_uri, selector, options)
158   return super unless options.respond_to?(:proxy)
159 
160   if (next_proxy = request_uri.find_proxy)
161     return super(request_uri, selector, options.merge(proxy: Parameters.new(uri: next_proxy)))
162   end
163 
164   proxy = options.proxy
165 
166   return super unless proxy
167 
168   next_proxy = proxy.uri
169 
170   raise ProxyError, "Failed to connect to proxy" unless next_proxy
171 
172   raise ProxyError,
173         "#{next_proxy.scheme}: unsupported proxy protocol" unless options.supported_proxy_protocols.include?(next_proxy.scheme)
174 
175   if (no_proxy = proxy.no_proxy)
176     no_proxy = no_proxy.join(",") if no_proxy.is_a?(Array)
177 
178     # TODO: setting proxy to nil leaks the connection object in the pool
179     return super(request_uri, selector, options.merge(proxy: nil)) unless URI::Generic.use_proxy?(request_uri.host, next_proxy.host,
180                                                                                                   next_proxy.port, no_proxy)
181   end
182 
183   super(request_uri, selector, options.merge(proxy: proxy))
184 end