Object
A response sent to the client.
Close any resource used by the response
# File lib/thin/response.rb, line 76
76: def close
77: @body.close if @body.respond_to?(:close)
78: 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 83
83: def each
84: yield head
85: if @body.is_a?(String)
86: yield @body
87: else
88: @body.each { |chunk| yield chunk }
89: end
90: end
Top header of the response, containing the status code and response headers.
# File lib/thin/response.rb, line 39
39: def head
40: "HTTP/1.1 #{@status} #{HTTP_STATUS_CODES[@status.to_i]}\r\n#{headers_output}\r\n"
41: end
Ruby 1.8 implementation. Respects Rack specs.
See rack.rubyforge.org/doc/files/SPEC.html
# File lib/thin/response.rb, line 49
49: def headers=(key_value_pairs)
50: key_value_pairs.each do |k, vs|
51: vs.each { |v| @headers[k] = v.chomp } if vs
52: end if key_value_pairs
53: end
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 62
62: def headers=(key_value_pairs)
63: key_value_pairs.each do |k, vs|
64: next unless vs
65: if vs.is_a?(String)
66: vs.each_line { |v| @headers[k] = v.chomp }
67: else
68: vs.each { |v| @headers[k] = v.chomp }
69: end
70: end if key_value_pairs
71: end
String representation of the headers to be sent in the response.
# File lib/thin/response.rb, line 29
29: def headers_output
30: # Set default headers
31: @headers[CONNECTION] = persistent? ? KEEP_ALIVE : CLOSE
32: @headers[SERVER] = Thin::SERVER
33:
34: @headers.to_s
35: end
Tell the client the connection should stay open
# File lib/thin/response.rb, line 93
93: def persistent!
94: @persistent = true
95: 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 100
100: def persistent?
101: (@persistent && @headers.has_key?(CONTENT_LENGTH)) || PERSISTENT_STATUSES.include?(@status)
102: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.