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
150 def find_connection(request_uri, selector, options)
151   return super unless options.respond_to?(:proxy)
152 
153   if (next_proxy = request_uri.find_proxy)
154     return super(request_uri, selector, options.merge(proxy: Parameters.new(uri: next_proxy)))
155   end
156 
157   proxy = options.proxy
158 
159   return super unless proxy
160 
161   next_proxy = proxy.uri
162 
163   raise Error, "Failed to connect to proxy" unless next_proxy
164 
165   raise Error,
166         "#{next_proxy.scheme}: unsupported proxy protocol" unless options.supported_proxy_protocols.include?(next_proxy.scheme)
167 
168   if (no_proxy = proxy.no_proxy)
169     no_proxy = no_proxy.join(",") if no_proxy.is_a?(Array)
170 
171     # TODO: setting proxy to nil leaks the connection object in the pool
172     return super(request_uri, selector, options.merge(proxy: nil)) unless URI::Generic.use_proxy?(request_uri.host, next_proxy.host,
173                                                                                                   next_proxy.port, no_proxy)
174   end
175 
176   super(request_uri, selector, options.merge(proxy: proxy))
177 end