Class: Mailkube::HttpResponse
- Inherits:
-
Object
- Object
- Mailkube::HttpResponse
- Defined in:
- lib/mailkube/transport.rb,
sig/mailkube/transport.rbs
Overview
One HTTP response, in the shape every adapter returns.
headers are stored exactly as the adapter supplied them, and read through #header, which
matches case-insensitively as HTTP requires.
Unlike the rest of this file, this class is public: it is the return type of the http:
adapter contract, so any adapter you write has to construct one.
Instance Attribute Summary collapse
-
#body ⇒ String
readonly
Returns the value of attribute body.
-
#headers ⇒ Hash[String, String]
readonly
Returns the value of attribute headers.
-
#status ⇒ Integer
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#header(name) ⇒ String?
Look a header up, case-insensitively.
-
#initialize(status:, headers: {}, body: "") ⇒ HttpResponse
constructor
A new instance of HttpResponse.
Constructor Details
#initialize(status:, headers: {}, body: "") ⇒ HttpResponse
Returns a new instance of HttpResponse.
34 |
# File 'lib/mailkube/transport.rb', line 34 def initialize(status:, headers: {}, body: "") = super |
Instance Attribute Details
#body ⇒ String (readonly)
Returns the value of attribute body.
16 17 18 |
# File 'sig/mailkube/transport.rbs', line 16 def body @body end |
#headers ⇒ Hash[String, String] (readonly)
Returns the value of attribute headers.
15 16 17 |
# File 'sig/mailkube/transport.rbs', line 15 def headers @headers end |
#status ⇒ Integer (readonly)
Returns the value of attribute status.
14 15 16 |
# File 'sig/mailkube/transport.rbs', line 14 def status @status end |
Instance Method Details
#header(name) ⇒ String?
Look a header up, case-insensitively.
Both sides are downcased, rather than downcasing the argument and indexing a map assumed to
be lowercase already. That assumption used to be this class's documented contract, and since
the class is public — the http: seam means third-party adapters construct it — it was
an invariant the SDK asked for and could not enforce. An adapter that passed X-Request-Id
through in the server's own casing produced a silent nil for every header the SDK reads,
which is exactly how the request id could have stayed empty even after the gateway started
sending it. A scan over a handful of pairs costs nothing and cannot be got wrong from
outside.
49 50 51 52 53 |
# File 'lib/mailkube/transport.rb', line 49 def header(name) wanted = name.downcase headers.each { |key, value| return value if key.downcase == wanted } nil end |