A response sent to the client.
Error Responses
Response body, must respond to
each
.
Headers key-value hash
Status code
# File lib/thin/response.rb, line 26 def initialize @headers = Headers.new @status = 200 @persistent = false end
Close any resource used by the response
# File lib/thin/response.rb, line 81 def close @body.close if @body.respond_to?(:close) end
Yields each chunk of the response. To control the size of each chunk define
your own each
method on body
.
# File lib/thin/response.rb, line 88 def each yield head if @body.is_a?(String) yield @body else @body.each { |chunk| yield chunk } end end
Top header of the response, containing the status code and response headers.
# File lib/thin/response.rb, line 44 def head "HTTP/1.1 #{@status} #{HTTP_STATUS_CODES[@status.to_i]}\r\n#{headers_output}\r\n" end
Ruby 1.8 implementation. Respects Rack specs.
See rack.rubyforge.org/doc/files/SPEC.html
# File lib/thin/response.rb, line 54 def headers=(key_value_pairs) key_value_pairs.each do |k, vs| vs.each { |v| @headers[k] = v.chomp } if vs end if key_value_pairs end
String representation of the headers to be sent in the response.
# File lib/thin/response.rb, line 34 def headers_output # Set default headers @headers[CONNECTION] = persistent? ? KEEP_ALIVE : CLOSE @headers[SERVER] = Thin::SERVER @headers.to_s end
Tell the client the connection should stay open
# File lib/thin/response.rb, line 98 def persistent! @persistent = true end
Persistent connection must be requested as keep-alive from the server and have a Content-Length, or the response status must require that the connection remain open.
# File lib/thin/response.rb, line 105 def persistent? (@persistent && @headers.has_key?(CONTENT_LENGTH)) || PERSISTENT_STATUSES.include?(@status) end