Sha256: dcdc014a2993871864ba018de9b17f9b8e98f163798db1fb01eaa7bb20c642ea
Contents?: true
Size: 1.24 KB
Versions: 1
Compression:
Stored size: 1.24 KB
Contents
module Thin # A response sent to the client. class Response CONNECTION = 'Connection'.freeze SERVER = 'Server'.freeze CLOSE = 'close'.freeze # Status code attr_accessor :status # Response body, must respond to +each+. attr_accessor :body # Headers key-value hash attr_reader :headers def initialize @headers = Headers.new @status = 200 end # String representation of the headers # to be sent in the response. def headers_output @headers[CONNECTION] = CLOSE @headers[SERVER] = Thin::SERVER @headers.to_s end # Top header of the response, # containing the status code and response headers. def head "HTTP/1.1 #{@status} #{HTTP_STATUS_CODES[@status.to_i]}\r\n#{headers_output}\r\n" end def headers=(key_value_pairs) key_value_pairs.each do |k, vs| vs.each { |v| @headers[k] = v.chomp } end end # Close any resource used by the response def close @body.close if @body.respond_to?(:close) end # Yields each chunk of the response def each yield head @body.each do |chunk| yield chunk end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
thin-0.5.4-x86-mswin32-60 | lib/thin/response.rb |