class Async::HTTP::Protocol::HTTP10
Implements basic HTTP/1.1 request/response.
def keep_alive?(headers)
def keep_alive?(headers) headers[:connection] == KEEP_ALIVE end
def read_body(headers)
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
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) unless keep_alive?(request.headers) && keep_alive?(headers) @keep_alive = false break end end return false 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