Module: Faraday::Adapter::HTTPX::RequestMixin

Included in:
Faraday::Adapter::HTTPX, ParallelManager
Defined in:
lib/httpx/adapters/faraday.rb

Instance Method Summary collapse

Instance Method Details

#build_connection(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/httpx/adapters/faraday.rb', line 11

def build_connection(env)
  return @connection if defined?(@connection)

  @connection = ::HTTPX.plugin(:persistent).plugin(ReasonPlugin)
  @connection = @connection.with(@connection_options) unless @connection_options.empty?
  connection_opts = options_from_env(env)

  if (bind = env.request.bind)
    @bind = TCPSocket.new(bind[:host], bind[:port])
    connection_opts[:io] = @bind
  end
  @connection = @connection.with(connection_opts)

  if (proxy = env.request.proxy)
    proxy_options = { uri: proxy.uri }
    proxy_options[:username] = proxy.user if proxy.user
    proxy_options[:password] = proxy.password if proxy.password

    @connection = @connection.plugin(:proxy).with(proxy: proxy_options)
  end
  @connection = @connection.plugin(OnDataPlugin) if env.request.stream_response?

  @connection = @config_block.call(@connection) || @connection if @config_block
  @connection
end

#closeObject



37
38
39
40
# File 'lib/httpx/adapters/faraday.rb', line 37

def close
  @connection.close if @connection
  @bind.close if @bind
end