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.
17 18 19 20 21 22 |
# File 'lib/cuba.rb', line 17 def initialize(headers = {}) @status = nil @headers = headers @body = [] @length = 0 end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
14 15 16 |
# File 'lib/cuba.rb', line 14 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
15 16 17 |
# File 'lib/cuba.rb', line 15 def headers @headers end |
#status ⇒ Object
Returns the value of attribute status.
12 13 14 |
# File 'lib/cuba.rb', line 12 def status @status end |
Instance Method Details
#[](key) ⇒ Object
24 25 26 |
# File 'lib/cuba.rb', line 24 def [](key) @headers[key] end |
#[]=(key, value) ⇒ Object
28 29 30 |
# File 'lib/cuba.rb', line 28 def []=(key, value) @headers[key] = value end |
#delete_cookie(key, value = {}) ⇒ Object
53 54 55 |
# File 'lib/cuba.rb', line 53 def (key, value = {}) Rack::Utils.(@headers, key, value) end |
#finish ⇒ Object
45 46 47 |
# File 'lib/cuba.rb', line 45 def finish [@status, @headers, @body] end |
#redirect(path, status = 302) ⇒ Object
40 41 42 43 |
# File 'lib/cuba.rb', line 40 def redirect(path, status = 302) @headers[LOCATION] = path @status = status end |
#set_cookie(key, value) ⇒ Object
49 50 51 |
# File 'lib/cuba.rb', line 49 def (key, value) Rack::Utils.(@headers, key, value) end |
#write(str) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/cuba.rb', line 32 def write(str) s = str.to_s @length += s.bytesize @headers[Rack::CONTENT_LENGTH] = @length.to_s @body << s end |