Class: Cloudflare::HTTPResponse
- Inherits:
-
Object
- Object
- Cloudflare::HTTPResponse
- Defined in:
- lib/cloudflare_workers/http.rb
Overview
Lightweight response wrapper around the JS Response object. The body is read eagerly (text()) so callers see a plain Ruby String. ‘headers` is a frozen Hash with lowercased string keys.
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #[](name) ⇒ Object
-
#initialize(status:, headers:, body:, url:) ⇒ HTTPResponse
constructor
A new instance of HTTPResponse.
- #json ⇒ Object
- #ok? ⇒ Boolean
Constructor Details
#initialize(status:, headers:, body:, url:) ⇒ HTTPResponse
Returns a new instance of HTTPResponse.
36 37 38 39 40 41 |
# File 'lib/cloudflare_workers/http.rb', line 36 def initialize(status:, headers:, body:, url:) @status = status @headers = headers @body = body @url = url end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
34 35 36 |
# File 'lib/cloudflare_workers/http.rb', line 34 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
34 35 36 |
# File 'lib/cloudflare_workers/http.rb', line 34 def headers @headers end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
34 35 36 |
# File 'lib/cloudflare_workers/http.rb', line 34 def status @status end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
34 35 36 |
# File 'lib/cloudflare_workers/http.rb', line 34 def url @url end |
Instance Method Details
#[](name) ⇒ Object
51 52 53 |
# File 'lib/cloudflare_workers/http.rb', line 51 def [](name) @headers[name.to_s.downcase] end |
#json ⇒ Object
47 48 49 |
# File 'lib/cloudflare_workers/http.rb', line 47 def json JSON.parse(@body) end |
#ok? ⇒ Boolean
43 44 45 |
# File 'lib/cloudflare_workers/http.rb', line 43 def ok? @status >= 200 && @status < 300 end |