class Tansu::Response

Public Class Methods

new(body = [], status = 200, header = {}) click to toggle source
Calls superclass method
# File lib/tansu/response.rb, line 3
def initialize(body = [], status = 200, header = {})
  super body, status, header

  headers['Content-Type'] ||= 'text/html'
end

Public Instance Methods

finish() click to toggle source
# File lib/tansu/response.rb, line 9
def finish
  drop_content_info if drop_content_info?

  ret = drop_body? ? drop_body : body

  headers['Content-Length'] = content_length.to_s if need_content_length?

  [status.to_i, headers, ret]
end

Private Instance Methods

content_length() click to toggle source
# File lib/tansu/response.rb, line 31
def content_length
  body.inject(0) { |a, e| a + Rack::Utils.bytesize(e) }
end
drop_body() click to toggle source
# File lib/tansu/response.rb, line 26
def drop_body
  close
  []
end
drop_body?() click to toggle source
# File lib/tansu/response.rb, line 43
def drop_body?
  [204, 205, 304].include?(status.to_i)
end
drop_content_info() click to toggle source
# File lib/tansu/response.rb, line 21
def drop_content_info
  headers.delete 'Content-Type'
  headers.delete 'Content-Length'
end
drop_content_info?() click to toggle source
# File lib/tansu/response.rb, line 39
def drop_content_info?
  status.to_i / 100 == 1 or drop_body?
end
need_content_length?() click to toggle source
# File lib/tansu/response.rb, line 35
def need_content_length?
  headers['Content-Type'] && !headers['Content-Length'] && Array === body
end