kennethreitz/requests — pull request #646 by mkomitee (2012-06-01 20:58:18+00:00)
Title: Allowing hooks to return responses that indicate errors

Since response objects for failures (4xx/5xx responses) evaluate to False
in a boolean context, any hook which returns such a failure response will
evaluate to False.

The way hooks were setup, any failure response resulting from a hook would
be ignored, and the initial response before it got processed by the hook
would be substituted in its place. This commit changes that logic to test
for None so that hooks that return failures can do so.

This would close out issue 644 (https://github.com/kennethreitz/requests/issues/644) which I opened earlier. It has some discussion about my findings, so you may want to look there for reference.

I've run the tests before and after this and the only tests that break as a result of this (as far as I can tell since I'm running python 2.6) are those in test_DIGESTAUTH_WRONG_HTTP_401_GET. That's because the bug that this fixes was hiding a bug in httpbin which is returning a 403 instead of a 401 on a failed digest authentication (it gets http basic right). I've submitted a pull request for httpbin that should address that (https://github.com/kennethreitz/httpbin/pull/48).