Set content type before authentication
authorPaul <paultax@gmail.com>
Fri, 27 Jul 2012 11:18:13 +0000 (19:18 +0800)
committerPaul <paultax@gmail.com>
Fri, 27 Jul 2012 11:18:13 +0000 (19:18 +0800)
AWS S3 authentication adds content type header (when it exist) to
canonical string that is signed. Since it is set after authentication
is done authentication on S3 fails

requests/models.py

index 2c0c7bdd7d2b53bcfc7b640064fdc01e9cb688c2..085be553ca8f637a5f1bff04d97fc4b6f8582146 100644 (file)
@@ -486,21 +486,6 @@ class Request(object):
         body = None
         content_type = None
 
-        # Use .netrc auth if none was provided.
-        if not self.auth and self.config.get('trust_env'):
-            self.auth = get_netrc_auth(url)
-
-        if self.auth:
-            if isinstance(self.auth, tuple) and len(self.auth) == 2:
-                # special-case basic HTTP auth
-                self.auth = HTTPBasicAuth(*self.auth)
-
-            # Allow auth to make its changes.
-            r = self.auth(self)
-
-            # Update self to reflect the auth changes.
-            self.__dict__.update(r.__dict__)
-
         # Multi-part file uploads.
         if self.files:
             (body, content_type) = self._encode_files(self.files)
@@ -517,6 +502,21 @@ class Request(object):
         if (content_type) and (not 'content-type' in self.headers):
             self.headers['Content-Type'] = content_type
 
+        # Use .netrc auth if none was provided.
+        if not self.auth and self.config.get('trust_env'):
+            self.auth = get_netrc_auth(url)
+
+        if self.auth:
+            if isinstance(self.auth, tuple) and len(self.auth) == 2:
+                # special-case basic HTTP auth
+                self.auth = HTTPBasicAuth(*self.auth)
+
+            # Allow auth to make its changes.
+            r = self.auth(self)
+
+            # Update self to reflect the auth changes.
+            self.__dict__.update(r.__dict__)
+
         _p = urlparse(url)
         no_proxy = filter(lambda x:x.strip(), self.proxies.get('no', '').split(','))
         proxy = self.proxies.get(_p.scheme)