-
Notifications
You must be signed in to change notification settings - Fork 323
Timeouts
Daniel Weinmann edited this page May 24, 2018
·
9 revisions
By default, the HTTP gem does not enforce timeout on a request. You can enable per operation timeouts (each read/write/connect call) or global timeouts (sum of all read/write/connect calls) by configuring them through the chaining API.
Per operation timeouts are what Net::HTTP
and the majority of HTTP clients do:
HTTP.timeout(:per_operation, :write => 2, :connect => 5, :read => 10)
.get "http://example.com"
# For convenience, you can omit timeout type in this case. So following has
# same result as the above:
HTTP.timeout(:write => 2, :connect => 5, :read => 10).get "http://example.com"
Global timeouts let you set an upper bound of how long a request can take,
without having to rely on Timeout.timeout
:
HTTP.timeout(:global, :write => 1, :connect => 1, :read => 1)
.get "http://example.com"
Uses a timeout of 3 seconds, for the entire get
call.