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

Defined in:
lib/httpx/plugins/proxy.rb,
sig/plugins/proxy.rbs

Instance Method Summary collapse

Instance Method Details

#find_connection(request_uri, selector, options) ⇒ Object

Raises:



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/httpx/plugins/proxy.rb', line 189

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

  return super unless @proxy_parameters

  next_proxy = @proxy_parameters.uri

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

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

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

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

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

#initialize ⇒ Object



179
180
181
182
# File 'lib/httpx/plugins/proxy.rb', line 179

def initialize(*)
  super
  @proxy_parameters = @options.proxy
end

#initialize_dup(other) ⇒ Object



184
185
186
187
# File 'lib/httpx/plugins/proxy.rb', line 184

def initialize_dup(other)
  @proxy_parameters = other.instance_variable_get(:@proxy_parameters)
  super
end