Sha256: cb605c19eca4e08cea40541c0d3a2686bbe873249ee2791f31fd2c8621c0887b

Contents?: true

Size: 1.29 KB

Versions: 39

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

module HTTPX
  module Plugins
    # This plugin implements a session that persists connections over the duration of the process.
    #
    # This will improve connection reuse in a long-running process.
    #
    # One important caveat to note is, although this session might not close connections,
    # other sessions from the same process that don't have this plugin turned on might.
    #
    # This session will still be able to work with it, as if, when expecting a connection
    # terminated by a different session, it will just retry on a new one and keep it open.
    #
    # This plugin is also not recommendable when connecting to >9000 (like, a lot) different origins.
    # So when you use this, make sure that you don't fall into this trap.
    #
    # https://gitlab.com/os85/httpx/wikis/Persistent
    #
    module Persistent
      def self.load_dependencies(klass)
        max_retries = if klass.default_options.respond_to?(:max_retries)
          [klass.default_options.max_retries, 1].max
        else
          1
        end
        klass.plugin(:retries, max_retries: max_retries, retry_change_requests: true)
      end

      def self.extra_options(options)
        options.merge(persistent: true)
      end
    end
    register_plugin :persistent, Persistent
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
httpx-1.3.4 lib/httpx/plugins/persistent.rb
httpx-1.3.3 lib/httpx/plugins/persistent.rb
httpx-1.3.2 lib/httpx/plugins/persistent.rb
httpx-1.3.1 lib/httpx/plugins/persistent.rb
httpx-1.3.0 lib/httpx/plugins/persistent.rb
httpx-1.2.6 lib/httpx/plugins/persistent.rb
httpx-1.2.4 lib/httpx/plugins/persistent.rb
httpx-1.2.3 lib/httpx/plugins/persistent.rb
httpx-1.2.2 lib/httpx/plugins/persistent.rb
httpx-1.2.1 lib/httpx/plugins/persistent.rb
httpx-1.2.0 lib/httpx/plugins/persistent.rb
httpx-1.1.5 lib/httpx/plugins/persistent.rb
httpx-1.1.4 lib/httpx/plugins/persistent.rb
httpx-1.1.3 lib/httpx/plugins/persistent.rb
httpx-1.1.2 lib/httpx/plugins/persistent.rb
httpx-1.1.1 lib/httpx/plugins/persistent.rb
httpx-1.1.0 lib/httpx/plugins/persistent.rb
httpx-1.0.2 lib/httpx/plugins/persistent.rb
httpx-0.24.7 lib/httpx/plugins/persistent.rb
httpx-1.0.1 lib/httpx/plugins/persistent.rb