Method: HTTPX::Connection#send

Defined in:
lib/httpx/connection.rb

#send(request) ⇒ Object



289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# File 'lib/httpx/connection.rb', line 289

def send(request)
  return @coalesced_connection.send(request) if @coalesced_connection

  if @parser && !@write_buffer.full?
    if @response_received_at && @keep_alive_timeout &&
       Utils.elapsed_time(@response_received_at) > @keep_alive_timeout
      # when pushing a request into an existing connection, we have to check whether there
      # is the possibility that the connection might have extended the keep alive timeout.
      # for such cases, we want to ping for availability before deciding to shovel requests.
      log(level: 3) { "keep alive timeout expired, pinging connection..." }
      @pending << request
      transition(:active) if @state == :inactive
      parser.ping
      request.ping!
      return
    end

    send_request_to_parser(request)
  else
    @pending << request
  end
end