class Async::HTTP::Protocol::HTTP10

Implements basic HTTP/1.1 request/response.

def persistent?(headers)

def persistent?(headers)
	if connection = headers[CONNECTION]
		return connection.include?(KEEP_ALIVE)
	else
		return false
	end
end

def read_body(headers)

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

def receive_requests(task: Task.current)

Server loop.
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

def version

def version
	VERSION
end

def write_body(body, chunked = false)

def write_body(body, chunked = false)
	# We don't support chunked encoding.
	super(body, chunked)
end

def write_persistent_header

def write_persistent_header
	@stream.write("Connection: keep-alive\r\n") if @persistent
end