Class: Thin::Response

Class Thin::Response < Object

(in files lib/thin/response.rb )

A response sent to the client.

Includes

Methods

Public Class new()

    # File lib/thin/response.rb, line 19
19:     def initialize
20:       @headers    = Headers.new
21:       @status     = 200
22:       @persistent = false
23:     end

Public Instance close()

Close any resource used by the response

    # File lib/thin/response.rb, line 74
74:     def close
75:       @body.close if @body.respond_to?(:close)
76:     end

Public Instance each() {|head| ...}

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 81
81:     def each
82:       yield head
83:       if @body.is_a?(String)
84:         yield @body
85:       else
86:         @body.each { |chunk| yield chunk }
87:       end
88:     end

Public Instance head()

Top header of the response, containing the status code and response headers.

    # File lib/thin/response.rb, line 37
37:     def head
38:       "HTTP/1.1 #{@status} #{HTTP_STATUS_CODES[@status.to_i]}\r\n#{headers_output}\r\n"
39:     end

Public Instance headers=(key_value_pairs)

Ruby 1.8 implementation. Respects Rack specs.

See rack.rubyforge.org/doc/files/SPEC.html

    # File lib/thin/response.rb, line 47
47:       def headers=(key_value_pairs)
48:         key_value_pairs.each do |k, vs|
49:           vs.each { |v| @headers[k] = v.chomp } if vs
50:         end if key_value_pairs
51:       end

Public Instance headers=(key_value_pairs)

Ruby 1.9 doesn‘t have a String#each anymore. Rack spec doesn‘t take care of that yet, for now we just use each but fallback to each_line on strings. I wish we could remove that condition. To be reviewed when a new Rack spec comes out.

    # File lib/thin/response.rb, line 60
60:       def headers=(key_value_pairs)
61:         key_value_pairs.each do |k, vs|
62:           next unless vs
63:           if vs.is_a?(String)
64:             vs.each_line { |v| @headers[k] = v.chomp }
65:           else
66:             vs.each { |v| @headers[k] = v.chomp }
67:           end
68:         end if key_value_pairs
69:       end

Public Instance headers_output()

String representation of the headers to be sent in the response.

    # File lib/thin/response.rb, line 27
27:     def headers_output
28:       # Set default headers
29:       @headers[CONNECTION] = persistent? ? KEEP_ALIVE : CLOSE
30:       @headers[SERVER]     = Thin::SERVER
31: 
32:       @headers.to_s
33:     end

Public Instance persistent!()

Tell the client the connection should stay open

    # File lib/thin/response.rb, line 91
91:     def persistent!
92:       @persistent = true
93:     end

Public Instance persistent?()

Persistent connection must be requested as keep-alive from the server and have a Content-Length.

    # File lib/thin/response.rb, line 97
97:     def persistent?
98:       @persistent && @headers.has_key?(CONTENT_LENGTH)
99:     end