From: Christopher Grebs Date: Tue, 27 Mar 2012 13:38:56 +0000 (+0200) Subject: Move pre_request to a more usable place, followup to #382 X-Git-Tag: v0.12.0~4^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f25901874ab9cb7c6be20f8126f744e13c49a041;p=services%2Fpython-requests.git Move pre_request to a more usable place, followup to #382 Having the hook called so late makes it impossible to overwrite the HTTP request calling behavior and set self.sent to True in case of possible cache matches for example. This way we can interfere before we waste any CPU time to calculate a request. --- diff --git a/requests/models.py b/requests/models.py index 881b7c1..dd73743 100644 --- a/requests/models.py +++ b/requests/models.py @@ -408,6 +408,10 @@ class Request(object): # Build the URL url = self.full_url + # Pre-request hook. + r = dispatch_hook('pre_request', self.hooks, self) + self.__dict__.update(r.__dict__) + # Logging if self.config.get('verbose'): self.config.get('verbose').write('%s %s %s\n' % ( @@ -537,10 +541,6 @@ class Request(object): # Attach Cookie header to request. self.headers['Cookie'] = cookie_header - # Pre-request hook. - r = dispatch_hook('pre_request', 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