lib/async/http/client.rb in async-http-0.76.0 vs lib/async/http/client.rb in async-http-0.77.0

- old
+ new

@@ -2,20 +2,21 @@ # Released under the MIT License. # Copyright, 2017-2024, by Samuel Williams. # Copyright, 2022, by Ian Ker-Seymer. -require 'io/endpoint' +require "io/endpoint" -require 'async/pool/controller' +require "async/pool/controller" -require 'protocol/http/body/completable' -require 'protocol/http/methods' +require "protocol/http/body/completable" +require "protocol/http/methods" -require 'traces/provider' +require "traces/provider" -require_relative 'protocol' +require_relative "protocol" +require_relative "body/finishable" module Async module HTTP DEFAULT_RETRIES = 3 DEFAULT_CONNECTION_LIMIT = nil @@ -138,45 +139,45 @@ end def inspect "#<#{self.class} authority=#{@authority.inspect}>" end - + Traces::Provider(self) do def call(request) attributes = { 'http.method': request.method, 'http.authority': request.authority || self.authority, 'http.scheme': request.scheme || self.scheme, 'http.path': request.path, } if protocol = request.protocol - attributes['http.protocol'] = protocol + attributes["http.protocol"] = protocol end if length = request.body&.length - attributes['http.request.length'] = length + attributes["http.request.length"] = length end - Traces.trace('async.http.client.call', attributes: attributes) do |span| + Traces.trace("async.http.client.call", attributes: attributes) do |span| if context = Traces.trace_context - request.headers['traceparent'] = context.to_s + request.headers["traceparent"] = context.to_s # request.headers['tracestate'] = context.state end super.tap do |response| if version = response&.version - span['http.version'] = version + span["http.version"] = version end if status = response&.status - span['http.status_code'] = status + span["http.status_code"] = status end if length = response.body&.length - span['http.response.length'] = length + span["http.response.length"] = length end end end end end @@ -184,13 +185,10 @@ protected def make_response(request, connection) response = request.call(connection) - # The connection won't be released until the body is completely read/released. - ::Protocol::HTTP::Body::Completable.wrap(response) do - @pool.release(connection) - end + response.pool = @pool return response end def make_pool(connection_limit)