Module: HTTPX::Plugins::Proxy::InstanceMethods

Defined in:
lib/httpx/plugins/proxy.rb

Instance Method Summary collapse

Instance Method Details

#find_connection(request_uri, selector, options) ⇒ Object

Raises:



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/httpx/plugins/proxy.rb', line 150

def find_connection(request_uri, selector, options)
  return super unless options.respond_to?(:proxy)

  if (next_proxy = request_uri.find_proxy)
    return super(request_uri, selector, options.merge(proxy: Parameters.new(uri: next_proxy)))
  end

  proxy = options.proxy

  return super unless proxy

  next_proxy = proxy.uri

  raise Error, "Failed to connect to proxy" unless next_proxy

  raise Error,
        "#{next_proxy.scheme}: unsupported proxy protocol" unless options.supported_proxy_protocols.include?(next_proxy.scheme)

  if (no_proxy = proxy.no_proxy)
    no_proxy = no_proxy.join(",") if no_proxy.is_a?(Array)

    # TODO: setting proxy to nil leaks the connection object in the pool
    return super(request_uri, selector, options.merge(proxy: nil)) unless URI::Generic.use_proxy?(request_uri.host, next_proxy.host,
                                                                                                  next_proxy.port, no_proxy)
  end

  super(request_uri, selector, options.merge(proxy: proxy))
end