Class: Spikard::Response
- Inherits:
-
Object
- Object
- Spikard::Response
- Defined in:
- lib/spikard/response.rb
Overview
:nodoc: Native-backed HTTP response facade generated from Rust metadata.
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#native_response ⇒ Object
readonly
Returns the value of attribute native_response.
-
#status_code ⇒ Object
Returns the value of attribute status_code.
Instance Method Summary collapse
-
#initialize(content: nil, body: nil, status_code: 200, headers: nil, content_type: nil) ⇒ Response
constructor
A new instance of Response.
- #set_cookie(name, value, **options) ⇒ Object
- #set_header(name, value) ⇒ Object
- #status ⇒ Object
- #to_native_response ⇒ Object
Constructor Details
#initialize(content: nil, body: nil, status_code: 200, headers: nil, content_type: nil) ⇒ Response
Returns a new instance of Response.
8 9 10 11 12 13 14 |
# File 'lib/spikard/response.rb', line 8 def initialize(content: nil, body: nil, status_code: 200, headers: nil, content_type: nil) @content = content.nil? ? body : content @status_code = Integer(status_code || 200) @headers = normalize_headers(headers) set_header('content-type', content_type) if content_type rebuild_native! end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
6 7 8 |
# File 'lib/spikard/response.rb', line 6 def content @content end |
#headers ⇒ Object
Returns the value of attribute headers.
6 7 8 |
# File 'lib/spikard/response.rb', line 6 def headers @headers end |
#native_response ⇒ Object (readonly)
Returns the value of attribute native_response.
6 7 8 |
# File 'lib/spikard/response.rb', line 6 def native_response @native_response end |
#status_code ⇒ Object
Returns the value of attribute status_code.
6 7 8 |
# File 'lib/spikard/response.rb', line 6 def status_code @status_code end |
Instance Method Details
#set_cookie(name, value, **options) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/spikard/response.rb', line 42 def (name, value, **) raise ArgumentError, 'cookie name required' if name.nil? || name.empty? header_value = ["#{name}=#{value}", *()].join('; ') set_header('set-cookie', header_value) end |
#set_header(name, value) ⇒ Object
37 38 39 40 |
# File 'lib/spikard/response.rb', line 37 def set_header(name, value) @headers[name.to_s] = value.to_s rebuild_native! end |
#status ⇒ Object
16 17 18 |
# File 'lib/spikard/response.rb', line 16 def status @status_code end |
#to_native_response ⇒ Object
49 50 51 |
# File 'lib/spikard/response.rb', line 49 def to_native_response @native_response end |