class RSence::Response

Classic WEBrick -compatible Response object for Rack. Implements only the methods used by the framework.

Public Class Methods

new() click to toggle source
# File lib/rsence/http/response.rb, line 31
def initialize
  @body = ResponseBody.new(1)
  @body[0] = ''
  @status = 200
  @header = {
    'Content-Type' => 'text/plain',
    'Server' => 'RSence'
  }
end

Public Instance Methods

[]=(header_key,header_val) click to toggle source
# File lib/rsence/http/response.rb, line 67
def []=(header_key,header_val)
  @header[camelize( header_key )] = header_val.to_s
end
body() click to toggle source
# File lib/rsence/http/response.rb, line 44
def body
  @body
end
body=(body_data) click to toggle source
# File lib/rsence/http/response.rb, line 40
def body=(body_data)
  @body = ResponseBody.new(1)
  @body[0] = @body.sanitize_body_data( body_data )
end
body_bytes() click to toggle source
# File lib/rsence/http/response.rb, line 47
def body_bytes
  bytes = 0
  @body.each do |part|
    if part.respond_to?(:to_s)
      bytes += part.to_s.bytesize
    else
      warn "body data part does not respond to to_s: #{part.inspect[0..100]}"
    end
  end
  return bytes.to_s
end
camelize( header_key ) click to toggle source
# File lib/rsence/http/response.rb, line 64
def camelize( header_key )
  header_key.capitalize.gsub(/\-([a-z])/) { '-'+$1.upcase }
end
content_type() click to toggle source
# File lib/rsence/http/response.rb, line 61
def content_type
  @header['Content-Type']
end
content_type=(new_content_type) click to toggle source
# File lib/rsence/http/response.rb, line 58
def content_type=(new_content_type)
  @header['Content-Type'] = new_content_type
end
header() click to toggle source
# File lib/rsence/http/response.rb, line 76
def header
  @header
end
status() click to toggle source
# File lib/rsence/http/response.rb, line 73
def status
  @status
end
status=(new_val) click to toggle source
# File lib/rsence/http/response.rb, line 70
def status=(new_val)
  @status = new_val.to_i
end