class Anthropic::Internal::Transport::PooledNetRequester
def execute(request)
-
(Array(Integer, Net::HTTPResponse, Enumerable
-))
Options Hash:
(**request)
-
:deadline
(Float
) -- -
:body
(Object
) -- -
:headers
(Hash{String=>String}
) -- -
:url
(URI::Generic
) -- -
:method
(Symbol
) --
Parameters:
-
request
(Hash{Symbol=>Object}
) -- .
Other tags:
- Api: - private
def execute(request) url, deadline = request.fetch_values(:url, :deadline) req = nil eof = false finished = false closing = nil # rubocop:disable Metrics/BlockLength enum = Enumerator.new do |y| with_pool(url, deadline: deadline) do |conn| next if finished req, closing = self.class.build_request(request) do self.class.calibrate_socket_timeout(conn, deadline) end self.class.calibrate_socket_timeout(conn, deadline) unless conn.started? conn.keep_alive_timeout = self.class::KEEP_ALIVE_TIMEOUT conn.start end self.class.calibrate_socket_timeout(conn, deadline) conn.request(req) do |rsp| y << [conn, req, rsp] break if finished rsp.read_body do |bytes| y << bytes.force_encoding(Encoding::BINARY) break if finished self.class.calibrate_socket_timeout(conn, deadline) end eof = true end end rescue Timeout::Error raise Anthropic::Errors::APITimeoutError.new(url: url, request: req) rescue StandardError raise Anthropic::Errors::APIConnectionError.new(url: url, request: req) end # rubocop:enable Metrics/BlockLength conn, _, response = enum.next body = Anthropic::Internal::Util.fused_enum(enum, external: true) do finished = true tap do enum.next rescue StopIteration nil end ensure conn.finish if !eof && conn&.started? closing&.call end [Integer(response.code), response, body] end