pre-send hook

#516
This commit is contained in:
Kenneth Reitz
2012-05-02 19:09:18 -04:00
parent efe5d13ed6
commit 8ac6b266c9
2 changed files with 8 additions and 1 deletions
+4 -1
View File
@@ -12,6 +12,9 @@ Available hooks:
A dictionary of the arguments being sent to Request().
``pre_request``:
The Request object, directly after being created.
``pre_send``:
The Request object, directly before being sent.
``post_request``:
@@ -25,7 +28,7 @@ Available hooks:
import traceback
HOOKS = ('args', 'pre_request', 'post_request', 'response')
HOOKS = ('args', 'pre_request', 'pre_send', 'post_request', 'response')
def dispatch_hook(key, hooks, hook_data):
+4
View File
@@ -570,6 +570,10 @@ class Request(object):
if cookie_header is not None:
self.headers['Cookie'] = cookie_header
# Pre-send hook.
r = dispatch_hook('pre_send', self.hooks, self)
self.__dict__.update(r.__dict__)
try:
# The inner try .. except re-raises certain exceptions as
# internal exception types; the outer suppresses exceptions