class Cuba::Response
Constants
- LOCATION
Attributes
body[R]
headers[R]
status[RW]
Public Class Methods
new(headers = {})
click to toggle source
# File lib/cuba.rb, line 26 def initialize(headers = {}) @status = nil @headers = headers @body = [] @length = 0 end
Public Instance Methods
[](key)
click to toggle source
# File lib/cuba.rb, line 33 def [](key) @headers[key] end
[]=(key, value)
click to toggle source
# File lib/cuba.rb, line 37 def []=(key, value) @headers[key] = value end
finish()
click to toggle source
# File lib/cuba.rb, line 72 def finish [@status, @headers, @body] end
html(str)
click to toggle source
Write response body as text/html
# File lib/cuba.rb, line 56 def html(str) @headers[Rack::CONTENT_TYPE] = ContentType::HTML write(str) end
json(str)
click to toggle source
Write response body as application/json
# File lib/cuba.rb, line 62 def json(str) @headers[Rack::CONTENT_TYPE] = ContentType::JSON write(str) end
redirect(path, status = 302)
click to toggle source
# File lib/cuba.rb, line 67 def redirect(path, status = 302) @headers[LOCATION] = path @status = status end
text(str)
click to toggle source
Write response body as text/plain
# File lib/cuba.rb, line 50 def text(str) @headers[Rack::CONTENT_TYPE] = ContentType::TEXT write(str) end
write(str)
click to toggle source
# File lib/cuba.rb, line 41 def write(str) s = str.to_s @length += s.bytesize @headers[Rack::CONTENT_LENGTH] = @length.to_s @body << s end