Method: HTTP::Chainable#timeout

Defined in:
lib/http/chainable.rb

#timeout(options = {}) ⇒ HTTP::Session #timeout(global_timeout) ⇒ HTTP::Session

Set timeout on the request

Examples:

HTTP.timeout(10).get("http://example.com")

Overloads:

  • #timeout(options = {}) ⇒ HTTP::Session

    Adds per operation timeouts to the request

    Parameters:

    • options (Hash) (defaults to: {})

    Options Hash (options):

    • :read (Float)

      Read timeout

    • :write (Float)

      Write timeout

    • :connect (Float)

      Connect timeout

    • :global (Float)

      Global timeout (combines with per-operation)

  • #timeout(global_timeout) ⇒ HTTP::Session

    Adds a global timeout to the full request

    Parameters:

    • global_timeout (Numeric)

Returns:



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/http/chainable.rb', line 53

def timeout(options)
  klass, options = case options
                   when Numeric then [HTTP::Timeout::Global, { global_timeout: options }]
                   when Hash    then resolve_timeout_hash(options)
                   when :null   then [HTTP::Timeout::Null, {}]
                   else raise ArgumentError,
                              "Use `.timeout(:null)`, " \
                              "`.timeout(global_timeout_in_seconds)` or " \
                              "`.timeout(connect: x, write: y, read: z)`."
                   end

  branch default_options.merge(
    timeout_class:   klass,
    timeout_options: options
  )
end