Class: EmmyHttp::Server::Response
- Inherits:
-
Object
- Object
- EmmyHttp::Server::Response
- Includes:
- ModelPack::Document
- Defined in:
- lib/emmy_http/server/response.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#finished ⇒ Object
writeonly
Sets the attribute finished.
-
#headers_sent ⇒ Object
writeonly
Sets the attribute headers_sent.
-
#keep_alive ⇒ Object
Returns the value of attribute keep_alive.
Instance Method Summary collapse
- #attach(conn) ⇒ Object
- #close(reason = nil) ⇒ Object
- #dettach ⇒ Object
- #finished? ⇒ Boolean
- #headers_sent? ⇒ Boolean
- #write_all ⇒ Object
- #write_body ⇒ Object
- #write_head ⇒ Object
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
13 14 15 |
# File 'lib/emmy_http/server/response.rb', line 13 def connection @connection end |
#finished=(value) ⇒ Object (writeonly)
Sets the attribute finished
15 16 17 |
# File 'lib/emmy_http/server/response.rb', line 15 def finished=(value) @finished = value end |
#headers_sent=(value) ⇒ Object (writeonly)
Sets the attribute headers_sent
14 15 16 |
# File 'lib/emmy_http/server/response.rb', line 14 def headers_sent=(value) @headers_sent = value end |
#keep_alive ⇒ Object
Returns the value of attribute keep_alive.
12 13 14 |
# File 'lib/emmy_http/server/response.rb', line 12 def keep_alive @keep_alive end |
Instance Method Details
#attach(conn) ⇒ Object
53 54 55 56 |
# File 'lib/emmy_http/server/response.rb', line 53 def attach(conn) @connection = conn listen conn, :close, :close end |
#close(reason = nil) ⇒ Object
47 48 49 50 51 |
# File 'lib/emmy_http/server/response.rb', line 47 def close(reason=nil) body.close if body.respond_to?(:close) terminate!(reason, self, connection) if reason dettach end |
#dettach ⇒ Object
58 59 60 61 62 63 |
# File 'lib/emmy_http/server/response.rb', line 58 def dettach if connection stop_listen connection, :close @connection = nil end end |
#finished? ⇒ Boolean
69 70 71 |
# File 'lib/emmy_http/server/response.rb', line 69 def finished? @finished end |
#headers_sent? ⇒ Boolean
65 66 67 |
# File 'lib/emmy_http/server/response.rb', line 65 def headers_sent? @headers_sent end |
#write_all ⇒ Object
17 18 19 20 |
# File 'lib/emmy_http/server/response.rb', line 17 def write_all write_head unless headers_sent? write_body unless finished? end |
#write_body ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/emmy_http/server/response.rb', line 38 def write_body if body.respond_to?(:each) body.each { |chunk| connection.send_data(chunk) } else connection.send_data(body) if body end @finished = true end |
#write_head ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/emmy_http/server/response.rb', line 22 def write_head raise ResponseError, "Invalid HTTP status" unless Server::HTTP_STATUS_CODES.key?(status) prepare_headers head = "HTTP/1.1 #{status} #{Server::HTTP_STATUS_CODES[status.to_i]}\r\n" headers.each do |n, v| head += "#{n}: #{v}\r\n" if v end head += "\r\n" connection.send_data(head) @headers_sent = true end |