lib/async/http/protocol/http10.rb in async-http-0.18.0 vs lib/async/http/protocol/http10.rb in async-http-0.19.0
- old
+ new
@@ -36,14 +36,16 @@
end
# Server loop.
def receive_requests
while request = Request.new(*self.read_request)
- status, headers, body = yield request
+ response = yield request
- write_response(request.version, status, headers, body)
+ response.version ||= request.version
+ write_response(response.version, response.status, response.headers, response.body)
+
unless keep_alive?(request.headers) && keep_alive?(headers)
@keep_alive = false
break
end
@@ -51,21 +53,21 @@
return false
end
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)
+ # We don't support chunked encoding.
+ super(body, false)
end
def read_body(headers)
- if content_length = headers['content-length']
- return @stream.read(Integer(content_length))
- # elsif !keep_alive?(headers)
- # return @stream.read
+ 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.
+ if !keep_alive?(headers)
+ return Body::Remainder.new(@stream)
end
end
end
end
end