Parent

Thin::Response

A response sent to the client.

Constants

CONNECTION
CLOSE
KEEP_ALIVE
SERVER
CONTENT_LENGTH

Attributes

status[RW]

Status code

body[RW]

Response body, must respond to each.

headers[R]

Headers key-value hash

Public Class Methods

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

Public Instance Methods

close() click to toggle source

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
each() click to toggle source

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
head() click to toggle source

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
headers=(key_value_pairs) click to toggle source

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
headers=(key_value_pairs) click to toggle source

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
headers_output() click to toggle source

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
persistent!() click to toggle source

Tell the client the connection should stay open

    # File lib/thin/response.rb, line 91
91:     def persistent!
92:       @persistent = true
93:     end
persistent?() click to toggle source

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

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.