Class: Sinatra::Response

Inherits:
Rack::Response
  • Object
show all
Defined in:
lib/sinatra/base.rb

Overview

The response object. See Rack::Response and Rack::Response::Helpers for more info: http://rubydoc.info/github/rack/rack/master/Rack/Response http://rubydoc.info/github/rack/rack/master/Rack/Response/Helpers

Constant Summary collapse

DROP_BODY_RESPONSES =
[204, 304]

Instance Method Summary collapse

Constructor Details

#initializeResponse

Returns a new instance of Response.



136
137
138
139
# File 'lib/sinatra/base.rb', line 136

def initialize(*)
  super
  headers['Content-Type'] ||= 'text/html'
end

Instance Method Details

#body=(value) ⇒ Object



141
142
143
144
# File 'lib/sinatra/base.rb', line 141

def body=(value)
  value = value.body while Rack::Response === value
  @body = String === value ? [value.to_str] : value
end

#eachObject



146
147
148
# File 'lib/sinatra/base.rb', line 146

def each
  block_given? ? super : enum_for(:each)
end

#finishObject



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/sinatra/base.rb', line 150

def finish
  result = body

  if 
    headers.delete "Content-Length"
    headers.delete "Content-Type"
  end

  if drop_body?
    close
    result = []
  end

  if calculate_content_length?
    # if some other code has already set Content-Length, don't muck with it
    # currently, this would be the static file-handler
    headers["Content-Length"] = body.inject(0) { |l, p| l + p.bytesize }.to_s
  end

  [status.to_i, headers, result]
end