Module: Nitro::Response
- Included in:
- Context
- Defined in:
- lib/nitro/cgi/response.rb,
lib/nitro/test/context.rb
Overview
Override the default Response implementation to include methods useful for testing.
Instance Attribute Summary collapse
-
#response_cookies ⇒ Object
The Response cookies.
-
#response_headers ⇒ Object
The Response headers.
-
#status ⇒ Object
The Response status.
Instance Method Summary collapse
-
#add_cookie(cookie, value = nil) ⇒ Object
(also: #send_cookie)
Add a cookie to the response.
-
#content_type ⇒ Object
Return the content type for this response.
-
#content_type=(ctype) ⇒ Object
Set the content type for this response.
- #redirect? ⇒ Boolean
- #redirect_url ⇒ Object
- #response_cookie(name) ⇒ Object
- #status_ok? ⇒ Boolean
Instance Attribute Details
#response_cookies ⇒ Object
The Response cookies.
17 18 19 |
# File 'lib/nitro/cgi/response.rb', line 17 def @response_cookies end |
#response_headers ⇒ Object
The Response headers.
13 14 15 |
# File 'lib/nitro/cgi/response.rb', line 13 def response_headers @response_headers end |
#status ⇒ Object
The Response status.
9 10 11 |
# File 'lib/nitro/cgi/response.rb', line 9 def status @status end |
Instance Method Details
#add_cookie(cookie, value = nil) ⇒ Object Also known as:
Add a cookie to the response. Better use this method to avoid precreating the cookies array for every request.
Examples
add_cookie(‘nsid’, ‘gmosx’) add_cookie(Cookie.new(‘nsid’, ‘gmosx’)
40 41 42 43 44 45 46 |
# File 'lib/nitro/cgi/response.rb', line 40 def (, value = nil) if value (@response_cookies ||= []) << Cookie.new(, value) else (@response_cookies ||= []) << end end |
#content_type ⇒ Object
Return the content type for this response.
21 22 23 |
# File 'lib/nitro/cgi/response.rb', line 21 def content_type @response_headers['Content-Type'] end |
#content_type=(ctype) ⇒ Object
Set the content type for this response.
27 28 29 |
# File 'lib/nitro/cgi/response.rb', line 27 def content_type=(ctype) @response_headers['Content-Type'] = ctype end |
#redirect? ⇒ Boolean
24 25 26 |
# File 'lib/nitro/test/context.rb', line 24 def redirect? (300..399).include?(@status) end |
#redirect_url ⇒ Object
28 29 30 |
# File 'lib/nitro/test/context.rb', line 28 def redirect_url @response_headers['location'] end |
#response_cookie(name) ⇒ Object
32 33 34 35 |
# File 'lib/nitro/test/context.rb', line 32 def (name) return nil unless @response_cookies @response_cookies.find { |c| c.name == name } end |
#status_ok? ⇒ Boolean
20 21 22 |
# File 'lib/nitro/test/context.rb', line 20 def status_ok? @status == 200 end |