Class: Rad::Http::Response
- Includes:
- RubyExt::OpenConstructor
- Defined in:
- lib/rad/http/_response.rb
Constant Summary collapse
- STATUS_MESSAGES =
{ ok: 200, not_found: 404, failed: 500, error: 500, redirect: 302 }
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#body_as_string ⇒ Object
def to_a [status, headers, body] end.
- #clear ⇒ Object
- #content_type ⇒ Object
- #content_type=(type) ⇒ Object
- #content_type? ⇒ Boolean
- #cookies ⇒ Object
-
#initialize(*args) ⇒ Response
constructor
A new instance of Response.
- #inspect ⇒ Object
- #location ⇒ Object
- #location=(location) ⇒ Object
- #redirect? ⇒ Boolean
- #status=(code_or_message) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Response
Returns a new instance of Response.
12 13 14 15 |
# File 'lib/rad/http/_response.rb', line 12 def initialize *args super clear end |
Class Method Details
.decode_status_message(message) ⇒ Object
63 64 65 |
# File 'lib/rad/http/_response.rb', line 63 def self. STATUS_MESSAGES[] end |
Instance Method Details
#==(other) ⇒ Object
40 41 42 |
# File 'lib/rad/http/_response.rb', line 40 def == other to_a2 == other end |
#body_as_string ⇒ Object
def to_a
[status, headers, body]
end
28 29 30 31 32 33 34 |
# File 'lib/rad/http/_response.rb', line 28 def body_as_string if @body.is_a? String @body else @body ? @body.join : "" end end |
#clear ⇒ Object
48 49 50 51 52 53 |
# File 'lib/rad/http/_response.rb', line 48 def clear @status = 200 @header = Rack::Utils::HeaderHash.new("Content-Type" => nil) @length = 0 @body = [] end |
#content_type ⇒ Object
18 |
# File 'lib/rad/http/_response.rb', line 18 def content_type; self["Content-Type"] end |
#content_type=(type) ⇒ Object
17 |
# File 'lib/rad/http/_response.rb', line 17 def content_type= type; self["Content-Type"] = type end |
#content_type? ⇒ Boolean
19 |
# File 'lib/rad/http/_response.rb', line 19 def content_type?; !!content_type end |
#cookies ⇒ Object
44 45 46 |
# File 'lib/rad/http/_response.rb', line 44 def self['Set-Cookie'] end |
#inspect ⇒ Object
36 37 38 |
# File 'lib/rad/http/_response.rb', line 36 def inspect to_a2.inspect end |
#location ⇒ Object
21 |
# File 'lib/rad/http/_response.rb', line 21 def location; self['Location'] end |
#location=(location) ⇒ Object
22 |
# File 'lib/rad/http/_response.rb', line 22 def location= location; self['Location'] = location end |
#redirect? ⇒ Boolean
76 77 78 |
# File 'lib/rad/http/_response.rb', line 76 def redirect? super or (body and body.include?('window.location')) end |
#status=(code_or_message) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/rad/http/_response.rb', line 55 def status= @status = if .is_a? Numeric else self.class.() || raise("unknown http status message '#{}'!") end end |