Module: Raw::Response
- Included in:
- Context
- Defined in:
- lib/raw/test/context.rb,
lib/raw/context/response.rb
Overview
HTTP Response. This module is included in Context.
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.
-
#body ⇒ Object
Return the output buffer.
-
#content_type ⇒ Object
Return the content type for this response.
-
#content_type=(ctype) ⇒ Object
Set the content type for this response.
- #redirect? ⇒ Boolean
- #redirect_uri ⇒ Object
- #response_cookie(name) ⇒ Object
- #status_ok? ⇒ Boolean
Instance Attribute Details
#response_cookies ⇒ Object
The Response cookies.
17 18 19 |
# File 'lib/raw/context/response.rb', line 17 def @response_cookies end |
#response_headers ⇒ Object
The Response headers.
13 14 15 |
# File 'lib/raw/context/response.rb', line 13 def response_headers @response_headers end |
#status ⇒ Object
The Response status.
9 10 11 |
# File 'lib/raw/context/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/raw/context/response.rb', line 40 def (, value = nil) if value (@response_cookies ||= []) << Cookie.new(, value) else (@response_cookies ||= []) << end end |
#body ⇒ Object
Return the output buffer.
51 52 53 |
# File 'lib/raw/context/response.rb', line 51 def body @output_buffer end |
#content_type ⇒ Object
Return the content type for this response.
21 22 23 |
# File 'lib/raw/context/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/raw/context/response.rb', line 27 def content_type=(ctype) @response_headers["Content-Type"] = ctype end |
#redirect? ⇒ Boolean
24 25 26 |
# File 'lib/raw/test/context.rb', line 24 def redirect? (300..399).include?(@status) end |
#redirect_uri ⇒ Object
28 29 30 |
# File 'lib/raw/test/context.rb', line 28 def redirect_uri @response_headers['location'] end |
#response_cookie(name) ⇒ Object
32 33 34 35 |
# File 'lib/raw/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/raw/test/context.rb', line 20 def status_ok? @status == 200 end |