Class: Async::HTTP::Protocol::HTTP10
- Defined in:
- lib/async/http/protocol/http10.rb
Overview
Implements basic HTTP/1.1 request/response.
Constant Summary collapse
- VERSION =
"HTTP/1.0".freeze
Constants inherited from HTTP11
Async::HTTP::Protocol::HTTP11::CLOSE, Async::HTTP::Protocol::HTTP11::CRLF, Async::HTTP::Protocol::HTTP11::KEEP_ALIVE
Instance Method Summary collapse
- #keep_alive?(headers) ⇒ Boolean
- #read_body(headers) ⇒ Object
-
#receive_requests ⇒ Object
Server loop.
- #version ⇒ Object
- #write_body(body, chunked = true) ⇒ Object
Methods inherited from HTTP11
#initialize, #multiplex, #read_request, #read_response, #reusable?, #send_request, #write_request, #write_response
Constructor Details
This class inherits a constructor from Async::HTTP::Protocol::HTTP11
Instance Method Details
#keep_alive?(headers) ⇒ Boolean
34 35 36 |
# File 'lib/async/http/protocol/http10.rb', line 34 def keep_alive?(headers) headers['connection'] == KEEP_ALIVE end |
#read_body(headers) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/async/http/protocol/http10.rb', line 63 def read_body(headers) if content_length = headers['content-length'] return @stream.read(Integer(content_length)) # elsif !keep_alive?(headers) # return @stream.read end end |
#receive_requests ⇒ Object
Server loop.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/async/http/protocol/http10.rb', line 39 def receive_requests while request = Request.new(*self.read_request) status, headers, body = yield request write_response(request.version, status, headers, body) unless keep_alive?(request.headers) && keep_alive?(headers) @keep_alive = false break end end return false end |
#version ⇒ Object
30 31 32 |
# File 'lib/async/http/protocol/http10.rb', line 30 def version VERSION end |
#write_body(body, chunked = true) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/async/http/protocol/http10.rb', line 55 def write_body(body, chunked = true) buffer = String.new body.each{|chunk| buffer << chunk} @stream.write("Content-Length: #{buffer.bytesize}\r\n\r\n") @stream.write(buffer) end |