Class: Async::HTTP::Protocol::HTTP10
- Defined in:
- lib/async/http/protocol/http10.rb
Overview
Implements basic HTTP/1.1 request/response.
Constant Summary collapse
- KEEP_ALIVE =
'keep-alive'.freeze
- VERSION =
"HTTP/1.0".freeze
Constants inherited from HTTP11
Async::HTTP::Protocol::HTTP11::CLOSE, Async::HTTP::Protocol::HTTP11::CONNECTION, Async::HTTP::Protocol::HTTP11::CRLF, Async::HTTP::Protocol::HTTP11::HOST
Instance Attribute Summary
Attributes inherited from HTTP11
Instance Method Summary collapse
- #persistent?(headers) ⇒ Boolean
- #read_body(headers) ⇒ Object
-
#receive_requests(task: Task.current) ⇒ Object
Server loop.
- #version ⇒ Object
- #write_body(body, chunked = false) ⇒ Object
- #write_persistent_header ⇒ Object
Methods inherited from HTTP11
#call, #initialize, #multiplex, #read_request, #read_response, #reusable?, #write_request, #write_response
Constructor Details
This class inherits a constructor from Async::HTTP::Protocol::HTTP11
Instance Method Details
#persistent?(headers) ⇒ Boolean
36 37 38 |
# File 'lib/async/http/protocol/http10.rb', line 36 def persistent?(headers) headers.delete(CONNECTION) == KEEP_ALIVE end |
#read_body(headers) ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/async/http/protocol/http10.rb', line 69 def read_body(headers) if body = super return body end # Technically, with HTTP/1.0, if no content-length is specified, we just need to read everything until the connection is closed. unless @persistent return Body::Remainder.new(@stream) end end |
#receive_requests(task: Task.current) ⇒ Object
Server loop.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/async/http/protocol/http10.rb', line 41 def receive_requests(task: Task.current) while @persistent request = Request.new(*self.read_request) unless persistent?(request.headers) @persistent = false end response = yield request response.version ||= request.version write_response(response.version, response.status, response.headers, response.body) # This ensures we yield at least once every iteration of the loop and allow other fibers to execute. task.yield end end |
#version ⇒ Object
32 33 34 |
# File 'lib/async/http/protocol/http10.rb', line 32 def version VERSION end |
#write_body(body, chunked = false) ⇒ Object
64 65 66 67 |
# File 'lib/async/http/protocol/http10.rb', line 64 def write_body(body, chunked = false) # We don't support chunked encoding. super(body, chunked) end |
#write_persistent_header ⇒ Object
60 61 62 |
# File 'lib/async/http/protocol/http10.rb', line 60 def write_persistent_header @stream.write("Connection: keep-alive\r\n") if @persistent end |