Class: Faraday::Adapter::NetHttp

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

Direct Known Subclasses

NetHttpPersistent

Constant Summary collapse

NET_HTTP_EXCEPTIONS =
[
  IOError,
  Errno::ECONNABORTED,
  Errno::ECONNREFUSED,
  Errno::ECONNRESET,
  Errno::EHOSTUNREACH,
  Errno::EINVAL,
  Errno::ENETUNREACH,
  Errno::EPIPE,
  Net::HTTPBadResponse,
  Net::HTTPHeaderSyntaxError,
  Net::ProtocolError,
  SocketError,
  Zlib::GzipFile::Error,
]

Constants inherited from Faraday::Adapter

CONTENT_LENGTH

Instance Attribute Summary

Attributes included from Parallelism

#supports_parallel

Instance Method Summary collapse

Methods included from Faraday::AutoloadHelper

#all_loaded_constants, #autoload_all, #load_autoloaded_constants

Methods included from Parallelism

#inherited, #supports_parallel?

Methods inherited from Middleware

dependency, inherited, loaded?, new

Methods included from MiddlewareRegistry

#fetch_middleware, #load_middleware, #lookup_middleware, #middleware_mutex, #register_middleware

Constructor Details

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

Returns a new instance of NetHttp.


31
32
33
34
# File 'lib/faraday/adapter/net_http.rb', line 31

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

Instance Method Details

#call(env) ⇒ Object


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/faraday/adapter/net_http.rb', line 36

def call(env)
  super
  with_net_http_connection(env) do |http|
    configure_ssl(http, env[:ssl]) if env[:url].scheme == 'https' and env[:ssl]
    configure_request(http, env[:request])

    begin
      http_response = perform_request(http, env)
    rescue *NET_HTTP_EXCEPTIONS => err
      if defined?(OpenSSL) && OpenSSL::SSL::SSLError === err
        raise Faraday::SSLError, err
      else
        raise Error::ConnectionFailed, err
      end
    end

    save_response(env, http_response.code.to_i, http_response.body || '', nil, http_response.message) do |response_headers|
      http_response.each_header do |key, value|
        response_headers[key] = value
      end
    end
  end

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