class Jeanine::Response

Attributes

action_variables[RW]
body[R]
headers[R]
status[RW]

Public Class Methods

new(body = [], status = 200, headers = { 'Content-Type' => 'text/html; charset=utf-8' }) click to toggle source
# File lib/jeanine/response.rb, line 10
def initialize(body = [], status = 200, headers = { 'Content-Type' => 'text/html; charset=utf-8' })
  @body = body
  @status = status
  @headers = headers
  @length = 0

  return if body == []
  if body.respond_to? :to_str
    write body.to_str
  elsif body.respond_to? :each
    body.each { |i| write i.to_s }
  else
    raise TypeError, 'body must #respond_to? #to_str or #each'
  end
end

Public Instance Methods

complete!() click to toggle source
# File lib/jeanine/response.rb, line 26
def complete!
  unless (100..199).include?(status) || status == 204
    headers['Content-Length'] = @length.to_s
  end
  [status, headers, body]
end
content_type=(type) click to toggle source
# File lib/jeanine/response.rb, line 33
def content_type=(type)
  headers['Content-Type'] = type
end
redirect_to(target, status = 302) click to toggle source
# File lib/jeanine/response.rb, line 37
def redirect_to(target, status = 302)
  self.status = status
  headers['Location'] = target
end
write(string) click to toggle source
# File lib/jeanine/response.rb, line 42
def write(string)
  s = string.to_s
  @length += s.bytesize

  body << s
end