1
0
Fork 0
mirror of https://github.com/rest-client/rest-client.git synced 2022-11-09 13:49:40 -05:00

Add docs on manually following redirection.

This commit is contained in:
Andy Brody 2016-06-06 00:44:21 -04:00
parent 1ce9a466f1
commit e10e3d9da8

View file

@ -177,6 +177,38 @@ end
➔ 404 Resource Not Found | text/html 282 bytes
```
### Manually following redirection
To disable automatic redirection, set `:max_redirects => 0`.
```ruby
>> RestClient::Request.execute(method: :get, url: 'http://httpbin.org/redirect/1')
=> RestClient::Response 200 "{\n "args":..."
>> RestClient::Request.execute(method: :get, url: 'http://httpbin.org/redirect/1', max_redirects: 0)
RestClient::Found: 302 Found
```
To manually follow redirection, you can call `Response#follow_redirection`. Or
you could of course inspect the result and choose custom behavior.
```ruby
>> RestClient::Request.execute(method: :get, url: 'http://httpbin.org/redirect/1', max_redirects: 0)
RestClient::Found: 302 Found
>> begin
RestClient::Request.execute(method: :get, url: 'http://httpbin.org/redirect/1', max_redirects: 0)
rescue RestClient::ExceptionWithResponse => err
end
>> err
=> #<RestClient::Found: 302 Found>
>> err.response
=> RestClient::Response 302 "<!DOCTYPE H..."
>> err.response.headers[:location]
=> "/get"
>> err.response.follow_redirection
=> RestClient::Response 200 "{\n "args":..."
```
## Result handling
The result of a `RestClient::Request` is a `RestClient::Response` object.