From: Ian Cordasco Date: Wed, 23 Jan 2013 16:51:37 +0000 (-0500) Subject: Only call the hook once. X-Git-Tag: v1.2.0~68^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1cfe59299b1f81a070704a6a519f1329b4393a7a;p=services%2Fpython-requests.git Only call the hook once. --- diff --git a/requests/models.py b/requests/models.py index 1aacdda..9ec7975 100644 --- a/requests/models.py +++ b/requests/models.py @@ -11,7 +11,7 @@ import collections import logging from io import BytesIO -from .hooks import default_hooks, HOOKS +from .hooks import default_hooks from .structures import CaseInsensitiveDict from .status_codes import codes diff --git a/requests/sessions.py b/requests/sessions.py index d3fc851..2687cb6 100644 --- a/requests/sessions.py +++ b/requests/sessions.py @@ -276,10 +276,6 @@ class Session(SessionRedirectMixin): # Prepare the Request. prep = req.prepare() - # If auth hooks are present, they aren't passed to `dispatch_hook` - # As such, we need to update the original hooks dictionary with them - hooks.update(prep.hooks) - # Send the request. resp = self.send(prep, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies) @@ -299,9 +295,6 @@ class Session(SessionRedirectMixin): resp = history.pop() resp.history = tuple(history) - # Response manipulation hook. - resp = dispatch_hook('response', hooks, resp) - return resp def get(self, url, **kwargs): @@ -375,8 +368,11 @@ class Session(SessionRedirectMixin): def send(self, request, **kwargs): """Send a given PreparedRequest.""" + hooks = request.hooks adapter = self.get_adapter(url=request.url) r = adapter.send(request, **kwargs) + # Response manipulation hooks + r = dispatch_hook('response', hooks, r) return r def get_adapter(self, url):