Class: Rad::Response

Inherits:
Rack::Response
  • Object
show all
Includes:
OpenConstructor
Defined in:
lib/rad/http/support/rack/response.rb

Constant Summary collapse

STATUS_MESSAGES =
{
  ok: 200,
  not_found: 404,
  failed: 500,
  error: 500,
  redirect: 301
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Response

Returns a new instance of Response.



13
14
15
16
# File 'lib/rad/http/support/rack/response.rb', line 13

def initialize *args
  super
  clear
end

Class Method Details

.decode_status_message(message) ⇒ Object



64
65
66
# File 'lib/rad/http/support/rack/response.rb', line 64

def self.decode_status_message message
  STATUS_MESSAGES[message]
end

Instance Method Details

#==(other) ⇒ Object



41
42
43
# File 'lib/rad/http/support/rack/response.rb', line 41

def == other
  to_a2 == other
end

#body_as_stringObject

def to_a

[status, headers, body]

end



29
30
31
32
33
34
35
# File 'lib/rad/http/support/rack/response.rb', line 29

def body_as_string
  if @body.is_a? String
    @body
  else
    @body ? @body.join : ""
  end
end

#clearObject



49
50
51
52
53
54
# File 'lib/rad/http/support/rack/response.rb', line 49

def clear
  @status = 200
  @header = Rack::Utils::HeaderHash.new("Content-Type" => nil)
  @length = 0
  @body = []
end

#content_typeObject



19
# File 'lib/rad/http/support/rack/response.rb', line 19

def content_type; self["Content-Type"] end

#content_type=(type) ⇒ Object



18
# File 'lib/rad/http/support/rack/response.rb', line 18

def content_type= type; self["Content-Type"] = type end

#content_type?Boolean

Returns:

  • (Boolean)


20
# File 'lib/rad/http/support/rack/response.rb', line 20

def content_type?; !!content_type end

#cookiesObject



45
46
47
# File 'lib/rad/http/support/rack/response.rb', line 45

def cookies
  self['Set-Cookie']
end

#inspectObject



37
38
39
# File 'lib/rad/http/support/rack/response.rb', line 37

def inspect
  to_a2.inspect
end

#locationObject



22
# File 'lib/rad/http/support/rack/response.rb', line 22

def location; self['Location'] end

#location=(location) ⇒ Object



23
# File 'lib/rad/http/support/rack/response.rb', line 23

def location= location; self['Location'] = location end

#redirect?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/rad/http/support/rack/response.rb', line 77

def redirect?
  super or (body and body.include?('window.location'))
end

#status=(code_or_message) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/rad/http/support/rack/response.rb', line 56

def status= code_or_message
  @status = if code_or_message.is_a? Numeric
    code_or_message
  else
    self.class.decode_status_message(code_or_message) || raise("unknown http status message '#{code_or_message}'!")
  end
end