Commit 87f036ce authored by HoneyryderChuck's avatar HoneyryderChuck
Browse files

Merge branch 'ping-timeout' into 'master'

new option: :ping_timeout

See merge request !456
parents bd3a58f2 8b035697
Loading
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -47,8 +47,8 @@ module HTTPX
    def initialize(uri, options)
      @current_session = @current_selector = @max_concurrent_requests =
                           @parser = @sibling = @coalesced_connection = @altsvc_connection =
                                                  @family = @io = @ssl_session = @timeout =
                                                                    @connected_at = @response_received_at = nil
                                                  @ping_timer = @family = @io = @ssl_session =
                                                                            @timeout = @connected_at = @response_received_at = nil

      @exhausted = @cloned = @main_sibling = false

@@ -956,10 +956,20 @@ module HTTPX
      return if parser.waiting_for_ping?

      parser.ping

      ping_timeout = @options.timeout[:ping_timeout]

      @ping_timer = @current_selector.after(ping_timeout) do
        error = PingTimeoutError.new(ping_timeout, "Timed out after #{ping_timeout} seconds")
        on_error(error)
      end

      call
    end

    def pong
      @ping_timer.cancel
      @ping_timer = nil
      @response_received_at = Utils.now
      @no_more_requests_counter = 0
      send_pending
+4 −0
Original line number Diff line number Diff line
@@ -48,6 +48,10 @@ module HTTPX
    end

    def reset
      if @ping_timer
        @ping_timer.cancel
        @ping_timer = nil
      end
      @max_requests = @options.max_requests || MAX_REQUESTS
      @parser.reset!
      @handshake_completed = false
+4 −1
Original line number Diff line number Diff line
@@ -72,9 +72,12 @@ module HTTPX
  # Error raised when there was a timeout while resolving a domain to an IP.
  class ResolveTimeoutError < TimeoutError; end

  # Error raise when there was a timeout waiting for readiness of the socket the request is related to.
  # Error raised when there was a timeout waiting for readiness of the socket the request is related to.
  class OperationTimeoutError < TimeoutError; end

  # Error raised when a connection liveness probe (aka ping) times out.
  class PingTimeoutError < TimeoutError; end

  # Error raised when there was an error while resolving a domain to an IP.
  class ResolveError < Error; end

+4 −2
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ module HTTPX
    WINDOW_SIZE = 1 << 14 # 16K
    MAX_BODY_THRESHOLD_SIZE = (1 << 10) * 112 # 112K
    KEEP_ALIVE_TIMEOUT = 20
    PING_TIMEOUT = 2
    SETTINGS_TIMEOUT = 10
    CLOSE_HANDSHAKE_TIMEOUT = 10
    CONNECT_TIMEOUT = READ_TIMEOUT = WRITE_TIMEOUT = 60
@@ -79,7 +80,7 @@ module HTTPX
    # :compress_request_body :: whether to auto-decompress response body (defaults to <tt>true</tt>)
    # :timeout :: hash of timeout configurations (supports <tt>:connect_timeout</tt>, <tt>:settings_timeout</tt>,
    #             <tt>:operation_timeout</tt>, <tt>:keep_alive_timeout</tt>, <tt>:read_timeout</tt>,  <tt>:write_timeout</tt>,
    #             <tt>:request_timeout</tt> and <tt>:total_request_timeout</tt>
    #             <tt>:request_timeout</tt>, <tt>:total_request_timeout</tt> and <tt>:ping_timeout</tt>,
    # :headers :: hash of HTTP headers (ex: <tt>{ "x-custom-foo" => "bar" }</tt>)
    # :max_response_body_size :: maximum size (in bytes) that the response body can consume (no threshold by default), after which an
    #                            error is raised.
@@ -568,6 +569,7 @@ module HTTPX
        close_handshake_timeout: CLOSE_HANDSHAKE_TIMEOUT,
        operation_timeout: OPERATION_TIMEOUT,
        keep_alive_timeout: KEEP_ALIVE_TIMEOUT,
        ping_timeout: PING_TIMEOUT,
        read_timeout: READ_TIMEOUT,
        write_timeout: WRITE_TIMEOUT,
        request_timeout: REQUEST_TIMEOUT,
+1 −0
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ module HTTPX
    @sibling: instance?
    @main_sibling: bool
    @no_more_requests_counter: Integer
    @ping_timer: Timers::Timer?


    def addresses: () -> Array[Resolver::Entry]?
Loading