Skip to content
Janko Marohnić edited this page May 21, 2017 · 7 revisions

Automatically following redirects

The HTTP.follow option can be used for automatically following redirects:

response = HTTP.follow
               .get("https://example.com")

Limiting number of redirects

A maximum of 5 subsequent redirects will be allowed by default (anything more will raise a HTTP::Redirector::TooManyRedirectsError), but you can change the limit with the :max_hops option:

response = HTTP.follow(max_hops: 3)
               .get("https://example.com")

Unsafe redirects

If a POST, PUT or DELETE request returns a 300, 301 or 302 redirect response, it won't be followed by default and HTTP::StateError will be raised. You can set :strict to false if you want these redirects to be followed, in which case the GET verb will be used for that redirect.

response = HTTP.follow(strict: false)
               .get("https://example.com")

Clone this wiki locally