class Async::HTTP::Protocol::HTTP10
Implements basic HTTP/1.1 request/response.
def keep_alive?(headers)
def keep_alive?(headers) headers[HTTP_CONNECTION] == KEEP_ALIVE end
def read_body(headers)
def read_body(headers) if content_length = headers[HTTP_CONTENT_LENGTH] return @stream.read(Integer(content_length)) # elsif !keep_alive?(headers) # return @stream.read end end
def receive_requests
def receive_requests while request = Request.new(*self.read_request) status, headers, body = yield request write_response(request.version, status, headers, body) break unless keep_alive?(request.headers) && keep_alive?(headers) end end
def version
def version VERSION end
def write_body(body, chunked = true)
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