Class: Faraday::Adapter::NetHttp

Inherits:
Faraday::Adapter show all
Defined in:
lib/faraday/adapter/net_http.rb

Constant Summary collapse

NET_HTTP_EXCEPTIONS =
exceptions.freeze

Instance Method Summary collapse

Constructor Details

#initialize(app = nil, opts = {}, &block) ⇒ NetHttp

Returns a new instance of NetHttp.



38
39
40
41
# File 'lib/faraday/adapter/net_http.rb', line 38

def initialize(app = nil, opts = {}, &block)
  @ssl_cert_store = nil
  super(app, opts, &block)
end

Instance Method Details

#build_connection(env) ⇒ Object



43
44
45
46
47
48
# File 'lib/faraday/adapter/net_http.rb', line 43

def build_connection(env)
  net_http_connection(env).tap do |http|
    configure_ssl(http, env[:ssl]) if env[:url].scheme == 'https' && env[:ssl]
    configure_request(http, env[:request])
  end
end

#call(env) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/faraday/adapter/net_http.rb', line 63

def call(env)
  super
  connection(env) do |http|
    perform_request(http, env)
  rescue *NET_HTTP_EXCEPTIONS => e
    raise Faraday::SSLError, e if defined?(OpenSSL) && e.is_a?(OpenSSL::SSL::SSLError)

    raise Faraday::ConnectionFailed, e
  end
  @app.call env
rescue Timeout::Error, Errno::ETIMEDOUT => e
  raise Faraday::TimeoutError, e
end

#net_http_connection(env) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/faraday/adapter/net_http.rb', line 50

def net_http_connection(env)
  proxy = env[:request][:proxy]
  port = env[:url].port || (env[:url].scheme == 'https' ? 443 : 80)
  if proxy
    Net::HTTP.new(env[:url].hostname, port,
                  proxy[:uri].hostname, proxy[:uri].port,
                  proxy[:user], proxy[:password],
                  nil, proxy[:uri].scheme == 'https')
  else
    Net::HTTP.new(env[:url].hostname, port, nil)
  end
end