Class: Mailfloss::Transport
- Inherits:
-
Object
- Object
- Mailfloss::Transport
- Defined in:
- lib/mailfloss/transport.rb,
sig/mailfloss.rbs
Overview
Low-level HTTP transport. Any object that responds to
call(method, url, headers, body) and returns an object with
status, headers and body (or an equivalent Hash) can be injected
into Mailfloss::Client via the transport: kwarg — this is the seam
used by the test suite.
Defined Under Namespace
Classes: Response
Constant Summary collapse
- CONNECTION_ERRORS =
Errors considered transient connection failures (retried by the client).
[ Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::EHOSTUNREACH, Errno::ETIMEDOUT, Errno::EPIPE, SocketError, EOFError, Net::OpenTimeout, Net::ReadTimeout, OpenSSL::SSL::SSLError ].freeze
Instance Method Summary collapse
- #call(method, url, headers, body) ⇒ Response
-
#initialize(timeout: 30) ⇒ Transport
constructor
A new instance of Transport.
Constructor Details
#initialize(timeout: 30) ⇒ Transport
Returns a new instance of Transport.
29 30 31 |
# File 'lib/mailfloss/transport.rb', line 29 def initialize(timeout: 30) @timeout = timeout end |
Instance Method Details
#call(method, url, headers, body) ⇒ Response
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/mailfloss/transport.rb', line 38 def call(method, url, headers, body) uri = URI.parse(url) request = build_request(method, uri, headers, body) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = uri.scheme == "https" http.open_timeout = @timeout http.read_timeout = @timeout http.write_timeout = @timeout if http.respond_to?(:write_timeout=) response = http.start { |conn| conn.request(request) } response_headers = {} response.each_header { |key, value| response_headers[key.downcase] = value } Response.new(response.code.to_i, response_headers, response.body) end |