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
164 def find_connection(request_uri, selector, options)
165   return super unless options.respond_to?(:proxy)
166 
167   if (next_proxy = request_uri.find_proxy)
168     return super(request_uri, selector, options.merge(proxy: Parameters.new(uri: next_proxy)))
169   end
170 
171   proxy = options.proxy
172 
173   return super unless proxy
174 
175   next_proxy = proxy.uri
176 
177   raise ProxyError, "Failed to connect to proxy" unless next_proxy
178 
179   raise ProxyError,
180         "#{next_proxy.scheme}: unsupported proxy protocol" unless options.supported_proxy_protocols.include?(next_proxy.scheme)
181 
182   if (no_proxy = proxy.no_proxy)
183     no_proxy = no_proxy.join(",") if no_proxy.is_a?(Array)
184 
185     # TODO: setting proxy to nil leaks the connection object in the pool
186     return super(request_uri, selector, options.merge(proxy: nil)) unless URI::Generic.use_proxy?(request_uri.host, next_proxy.host,
187                                                                                                   next_proxy.port, no_proxy)
188   end
189 
190   super(request_uri, selector, options.merge(proxy: proxy))
191 end