Module: Async::HTTP::Protocol::HTTP1::Server
- Defined in:
- lib/async/http/protocol/http1/server.rb
Instance Method Summary collapse
-
#each(task: Task.current) ⇒ Object
Server loop.
- #next_request ⇒ Object
Instance Method Details
#each(task: Task.current) ⇒ Object
Server loop.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/async/http/protocol/http1/server.rb', line 48 def each(task: Task.current) while request = next_request response = yield(request, self) return if @stream.closed? if response write_response(self.version, response.status, response.headers, response.body, request.head?) else # If the request failed to generate a response, it was an internal server error: write_response(self.version, 500, {}, nil) end # Gracefully finish reading the request body if it was not already done so. request.finish # This ensures we yield at least once every iteration of the loop and allow other fibers to execute. task.yield end end |
#next_request ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/async/http/protocol/http1/server.rb', line 29 def next_request # The default is true. return nil unless @persistent request = Request.new(self) unless persistent?(request.headers) @persistent = false end return request rescue # Bad Request write_response(self.version, 400, {}, nil) raise end |