lib/httpx/connection/http1.rb in httpx-0.16.1 vs lib/httpx/connection/http1.rb in httpx-0.17.0

- old
+ new

@@ -57,11 +57,16 @@ end def empty? # this means that for every request there's an available # partial response, so there are no in-flight requests waiting. - @requests.empty? || @requests.all? { |request| !request.response.nil? } + @requests.empty? || ( + # checking all responses can be time-consuming. Alas, as in HTTP/1, responses + # do not come out of order, we can get away with checking first and last. + !@requests.first.response.nil? && + (@requests.size == 1 || !@requests.last.response.nil?) + ) end def <<(data) @parser << data end @@ -258,11 +263,11 @@ end def set_protocol_headers(request) if !request.headers.key?("content-length") && request.body.bytesize == Float::INFINITY - request.chunk! + request.body.chunk! end connection = request.headers["connection"] connection ||= if request.options.persistent @@ -283,14 +288,13 @@ else "close" end end - { - "host" => (request.headers["host"] || request.authority), - "connection" => connection, - } + extra_headers = { "connection" => connection } + extra_headers["host"] = request.authority unless request.headers.key?("host") + extra_headers end def headline_uri(request) request.path end @@ -316,20 +320,22 @@ log { "<- " } @buffer << CRLF end def join_body(request) - return if request.empty? + return if request.body.empty? while (chunk = request.drain_body) log(color: :green) { "<- DATA: #{chunk.bytesize} bytes..." } log(level: 2, color: :green) { "<- #{chunk.inspect}" } @buffer << chunk throw(:buffer_full, request) if @buffer.full? end - raise request.drain_error if request.drain_error + return unless (error = request.drain_error) + + raise error end def join_trailers(request) return unless request.trailers? && request.callbacks_for?(:trailers) @@ -352,10 +358,10 @@ "www-authenticate" => "WWW-Authenticate", "http2-settings" => "HTTP2-Settings", }.freeze def capitalized(field) - UPCASED[field] || field.to_s.split("-").map(&:capitalize).join("-") + UPCASED[field] || field.split("-").map(&:capitalize).join("-") end end Connection.register "http/1.1", Connection::HTTP1 end