Class Sinatra::Response
In: lib/sinatra/base.rb
Parent: Rack::Response

Methods

finish   new   write  

Public Class methods

[Source]

    # File lib/sinatra/base.rb, line 27
27:     def initialize
28:       @status, @body = 200, []
29:       @header = Rack::Utils::HeaderHash.new({'Content-Type' => 'text/html'})
30:     end

Public Instance methods

[Source]

    # File lib/sinatra/base.rb, line 37
37:     def finish
38:       @body = block if block_given?
39:       if [204, 304].include?(status.to_i)
40:         header.delete "Content-Type"
41:         [status.to_i, header.to_hash, []]
42:       else
43:         body = @body || []
44:         body = [body] if body.respond_to? :to_str
45:         if header["Content-Length"].nil? && body.respond_to?(:to_ary)
46:           header["Content-Length"] = body.to_ary.
47:             inject(0) { |len, part| len + part.length }.to_s
48:         end
49:         [status.to_i, header.to_hash, body]
50:       end
51:     end

[Source]

    # File lib/sinatra/base.rb, line 32
32:     def write(str)
33:       @body << str.to_s
34:       str
35:     end

[Validate]