Class: Sinatra::Response
- Inherits:
-
Rack::Response
- Object
- Rack::Response
- Sinatra::Response
- Defined in:
- lib/sinatra/base.rb
Instance Method Summary collapse
- #finish ⇒ Object
-
#initialize ⇒ Response
constructor
A new instance of Response.
- #write(str) ⇒ Object
Constructor Details
#initialize ⇒ Response
Returns a new instance of Response.
27 28 29 30 |
# File 'lib/sinatra/base.rb', line 27 def initialize @status, @body = 200, [] @header = Rack::Utils::HeaderHash.new({'Content-Type' => 'text/html'}) end |
Instance Method Details
#finish ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/sinatra/base.rb', line 37 def finish @body = block if block_given? if [204, 304].include?(status.to_i) header.delete "Content-Type" [status.to_i, header.to_hash, []] else body = @body || [] body = [body] if body.respond_to? :to_str if header["Content-Length"].nil? && body.respond_to?(:to_ary) header["Content-Length"] = body.to_ary. inject(0) { |len, part| len + part.length }.to_s end [status.to_i, header.to_hash, body] end end |
#write(str) ⇒ Object
32 33 34 35 |
# File 'lib/sinatra/base.rb', line 32 def write(str) @body << str.to_s str end |