Skip to content
Zachary Anker edited this page Jul 5, 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(3)
  .get "http://example.com"

Uses a timeout of 3 seconds, for the entire get call.

Clone this wiki locally