kennethreitz/requests — pull request #1913 by zackw (2014-02-11 20:33:32+00:00)
Title: Improve API for manual redirection-following

I'd like to propose a bunch of bugfixes and API improvements to redirection resolution, particularly when it's being done manually (i.e. `allow_redirects=False` on the initial `send()`). These are all motivated by problems I encountered while trying to chase redirects for every single URL in the Alexa top million, which, as you might imagine, contains an awful lot of misconfiguredness (up to and including IMAP and SMTP servers on ports 80 and 443!)

The most significant change is the new `Session.resolve_one_redirect` method, which does what it says - it resolves *one* redirect. This turns out to be substantially more convenient for applications that need to do complicated processing on each redirect as it happens, than the existing `Session.resolve_redirects` generator. It goes along with `Response.is_redirect`, a new property that is the canonical home for the "is this a redirect" predicate.

The second most significant change is that each response in a redirection chain now has an accurate `.history` property, containing all responses up to but not including itself. As a side effect, I anti-resolved issue #1898 - `.history` is now always a *list*.

The third most significant change is that `resolve_one_redirect` and `resolve_redirects` do not need to be passed a bunch of arguments that were already passed to the initial `send`; concretely, all of `send`'s kwargs are cached on the `PreparedRequest` and reused thereafter.

Everything else is bugfixes.