Only call the hook once.
authorIan Cordasco <graffatcolmingov@gmail.com>
Wed, 23 Jan 2013 16:51:37 +0000 (11:51 -0500)
committerIan Cordasco <graffatcolmingov@gmail.com>
Wed, 23 Jan 2013 16:51:37 +0000 (11:51 -0500)
requests/models.py
requests/sessions.py

index 1aacdda..9ec7975 100644 (file)
@@ -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
 
index d3fc851..2687cb6 100644 (file)
@@ -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):