lib/httpx/connection/http1.rb in httpx-0.15.0 vs lib/httpx/connection/http1.rb in httpx-0.15.1

- old
+ new

@@ -261,16 +261,27 @@ if !request.headers.key?("content-length") && request.body.bytesize == Float::INFINITY request.chunk! end - requests_limit = [@max_requests, @requests.size].min - - connection = if request != @requests[requests_limit - 1] && - request.options.persistent && @max_requests != 1 - "keep-alive" + connection = if request.options.persistent + # when in a persistent connection, the request can't be at + # the edge of a renegotiation + if @requests.index(request) + 1 < @max_requests + "keep-alive" + else + "close" + end else - "close" + # when it's not a persistent connection, it sets "Connection: close" always + # on the last request of the possible batch (either allowed max requests, + # or if smaller, the size of the batch itself) + requests_limit = [@max_requests, @requests.size].min + if request != @requests[requests_limit - 1] + "keep-alive" + else + "close" + end end { "host" => (request.headers["host"] || request.authority), "connection" => connection,