Module: HTTPX::Plugins::Persistent

Defined in:
lib/httpx/plugins/persistent.rb,
sig/plugins/persistent.rbs

Overview

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

Defined Under Namespace

Modules: InstanceMethods

Class Method Summary collapse

Class Method Details

.extra_options(options) ⇒ Options

Parameters:

Returns:



34
35
36
# File 'lib/httpx/plugins/persistent.rb', line 34

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

.load_dependencies(klass) ⇒ void

This method returns an undefined value.

Parameters:



22
23
24
25
26
27
28
29
30
31
# File 'lib/httpx/plugins/persistent.rb', line 22

def load_dependencies(klass)
  klass.plugin(:fiber_concurrency)

  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)
end