Class: Thin::Response
- Inherits:
-
Object
- Object
- Thin::Response
- Defined in:
- lib/thin/response.rb
Overview
A response sent to the client.
Constant Summary collapse
- CONNECTION =
'Connection'.freeze
- CLOSE =
'close'.freeze
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
- #close ⇒ Object
- #content_type ⇒ Object
- #content_type=(type) ⇒ Object
- #head ⇒ Object
- #headers_output ⇒ Object
-
#initialize ⇒ Response
constructor
A new instance of Response.
- #start(status) {|@headers, @body| ... } ⇒ Object
- #to_s ⇒ Object
- #write(socket) ⇒ Object
Constructor Details
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
7 8 9 |
# File 'lib/thin/response.rb', line 7 def body @body end |
#headers ⇒ Object
Returns the value of attribute headers.
7 8 9 |
# File 'lib/thin/response.rb', line 7 def headers @headers end |
#status ⇒ Object
Returns the value of attribute status.
7 8 9 |
# File 'lib/thin/response.rb', line 7 def status @status end |
Instance Method Details
#close ⇒ Object
39 40 41 |
# File 'lib/thin/response.rb', line 39 def close @body.close end |
#content_type ⇒ Object
19 20 21 |
# File 'lib/thin/response.rb', line 19 def content_type @headers[CONTENT_TYPE] end |
#content_type=(type) ⇒ Object
15 16 17 |
# File 'lib/thin/response.rb', line 15 def content_type=(type) @headers[CONTENT_TYPE] = type end |
#head ⇒ Object
29 30 31 |
# File 'lib/thin/response.rb', line 29 def head "HTTP/1.1 #{@status} #{HTTP_STATUS_CODES[@status.to_i]}\r\n#{headers_output}\r\n" end |
#headers_output ⇒ Object
23 24 25 26 27 |
# File 'lib/thin/response.rb', line 23 def headers_output @headers[CONTENT_LENGTH] = @body.size @headers[CONNECTION] = CLOSE @headers.to_s end |
#start(status) {|@headers, @body| ... } ⇒ Object
43 44 45 46 |
# File 'lib/thin/response.rb', line 43 def start(status) @status = status yield @headers, @body end |
#to_s ⇒ Object
48 49 50 51 52 |
# File 'lib/thin/response.rb', line 48 def to_s out = '' write out out end |
#write(socket) ⇒ Object
33 34 35 36 37 |
# File 'lib/thin/response.rb', line 33 def write(socket) socket << head @body.rewind socket << @body.read end |