Class: Renee::Core::Response
- Inherits:
-
Rack::Response
- Object
- Rack::Response
- Renee::Core::Response
- Defined in:
- lib/renee_core/response.rb
Overview
The response object for a Renee request. Inherits from the Rack#Response
object.
Instance Method Summary collapse
-
#body(val = nil) ⇒ Object
Get or set the body of the response.
-
#body=(value) ⇒ Object
(also: #body_attr=)
Augment body to allow strings.
- #body_attr ⇒ Object
-
#finish ⇒ Object
Finishs the response based on the accumulated options.
-
#headers(attrs = {}) ⇒ Object
Get or set the headers of the response.
-
#status(val = nil) ⇒ Object
Get or set the status of the response.
-
#status_attr ⇒ Object
Alias status and body methods to allow redefinition.
Instance Method Details
#body(val = nil) ⇒ Object
Get or set the body of the response.
46 47 48 |
# File 'lib/renee_core/response.rb', line 46 def body(val=nil) val ? self.body_attr = val : self.body_attr end |
#body=(value) ⇒ Object Also known as: body_attr=
Augment body to allow strings.
13 14 15 16 |
# File 'lib/renee_core/response.rb', line 13 def body=(value) value = value.body while Rack::Response === value @body = String === value ? [value.to_str] : value end |
#body_attr ⇒ Object
21 |
# File 'lib/renee_core/response.rb', line 21 alias :body_attr :body |
#finish ⇒ Object
Finishs the response based on the accumulated options. Calculates the size of the body content length and removes headers for 1xx status codes.
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/renee_core/response.rb', line 65 def finish if status.to_i / 100 == 1 headers.delete "Content-Length" headers.delete "Content-Type" elsif Array === body and not [204, 304].include?(status.to_i) headers["Content-Length"] = body.inject(0) { |l, p| l + Rack::Utils.bytesize(p) }.to_s end status, headers, result = super [status, headers, result] end |
#headers(attrs = {}) ⇒ Object
Get or set the headers of the response.
59 60 61 |
# File 'lib/renee_core/response.rb', line 59 def headers(attrs={}) attrs ? attrs.each { |k, v| self[k.to_s] = v } : self.header end |
#status(val = nil) ⇒ Object
Get or set the status of the response.
33 34 35 |
# File 'lib/renee_core/response.rb', line 33 def status(val=nil) val ? self.status_attr = val : self.status_attr end |
#status_attr ⇒ Object
Alias status and body methods to allow redefinition
19 |
# File 'lib/renee_core/response.rb', line 19 alias :status_attr :status |