4 releases

Uses old Rust 2015

0.1.3 Apr 4, 2018
0.1.2 Apr 4, 2018
0.1.1 Apr 4, 2018
0.1.0 Apr 4, 2018

#26 in #follow

28 downloads per month

MIT license

18KB
341 lines

follow-redirects

Extension for hyper to follow HTTP redirects.

Documentation

Build Status crates.io

Example

extern crate hyper;
extern crate follow_redirects;

// 1. import the extension trait
use follow_redirects::ClientExt;

// ...
// 2. create a standard hyper client
let client = hyper::Client::new(&handle);

// ...
// 3. make a request that will follow redirects
let url = "http://docs.rs/hyper".parse().unwrap();
let future = client.follow_redirects().get(url);

lib.rs:

Extension for hyper to follow HTTP redirects.

Behaviour and Limitations

Supported Redirects

This crate supports all 5 redirect styles that are defined by the HTTP/1.1 spec. These include both "permanent" redirects (status codes 301 and 308) as well as "temporary" redirects (status codes 302, 303 and 307).

Encountering a 303 See Other response from the server will cause the client to change the request method to GET, and discard the request body before following the redirect.

Location Header

The client uses the Location HTTP header to determine the next url to follow the redirect to. Both relative (without a hostname) as well as absolute URLs (including schema and hostname) urls are supported.

When the Location header is missing in a response from the server, but the status code indicates a redirect, the client will return the response to the caller. You can detect this situation by checking the status code and headers of the returned response.

Buffering

In order to be able to replay the request body when following redirects other than 303 See Other, the client will buffer the request body in-memory before making the first request to the server.

Redirect Limit

To avoid following an endless chain of redirects, the client has a limit for the maximum number of redirects it will follow until giving up.

When the maximum number of redirects is reached, the client will simply return the last response to the caller. You can detect this situation by checking the status code of the returned response.

Security Considerations

In order to protect the confidentiality of authentication or session information passed along in a request, the client will strip authentication and cookie headers when following a redirect to a different host and port.

Redirects to the same host and port, but different paths will retain session information.

Example

extern crate hyper;
extern crate follow_redirects;

// 1. import the extension trait
use follow_redirects::ClientExt;

// ...
// 2. create a standard hyper client
let client = hyper::Client::new(&handle);

// ...
// 3. make a request that will follow redirects
let url = "http://docs.rs/hyper".parse().unwrap();
let future = client.follow_redirects().get(url);

Dependencies

~9MB
~153K SLoC