Class: Cuba::Response
- Inherits:
-
Object
- Object
- Cuba::Response
- Defined in:
- lib/cuba.rb
Constant Summary collapse
- LOCATION =
"Location".freeze
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #delete_cookie(key, value = {}) ⇒ Object
- #finish ⇒ Object
-
#initialize(headers = {}) ⇒ Response
constructor
A new instance of Response.
- #redirect(path, status = 302) ⇒ Object
- #set_cookie(key, value) ⇒ Object
- #write(str) ⇒ Object
Constructor Details
#initialize(headers = {}) ⇒ Response
Returns a new instance of Response.
18 19 20 21 22 23 |
# File 'lib/cuba.rb', line 18 def initialize(headers = {}) @status = nil @headers = headers @body = [] @length = 0 end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
15 16 17 |
# File 'lib/cuba.rb', line 15 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
16 17 18 |
# File 'lib/cuba.rb', line 16 def headers @headers end |
#status ⇒ Object
Returns the value of attribute status.
13 14 15 |
# File 'lib/cuba.rb', line 13 def status @status end |
Instance Method Details
#[](key) ⇒ Object
25 26 27 |
# File 'lib/cuba.rb', line 25 def [](key) @headers[key] end |
#[]=(key, value) ⇒ Object
29 30 31 |
# File 'lib/cuba.rb', line 29 def []=(key, value) @headers[key] = value end |
#delete_cookie(key, value = {}) ⇒ Object
54 55 56 |
# File 'lib/cuba.rb', line 54 def (key, value = {}) Rack::Utils.(@headers, key, value) end |
#finish ⇒ Object
46 47 48 |
# File 'lib/cuba.rb', line 46 def finish [@status, @headers, @body] end |
#redirect(path, status = 302) ⇒ Object
41 42 43 44 |
# File 'lib/cuba.rb', line 41 def redirect(path, status = 302) @headers[LOCATION] = path @status = status end |
#set_cookie(key, value) ⇒ Object
50 51 52 |
# File 'lib/cuba.rb', line 50 def (key, value) Rack::Utils.(@headers, key, value) end |
#write(str) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/cuba.rb', line 33 def write(str) s = str.to_s @length += s.bytesize @headers[Rack::CONTENT_LENGTH] = @length.to_s @body << s end |