diff --git a/tests/test-ufile.py b/tests/test-ufile.py index 7ef881b..6fc9165 100644 --- a/tests/test-ufile.py +++ b/tests/test-ufile.py @@ -35,7 +35,7 @@ AUTHORIZATION = "UCloud public-key:vex1mk5WI2fe/i5TzXm7QY19p64=" PARAMS = dict( UCloudPublicKey="public-key", - Signature="JHrQ1u087Gv0ktLlBAyfYclnI/I=", + Signature="i85wNCWK1eotra5GWAF9WfHfjsY=", Expires="1" ) diff --git a/ucloudauth/ufile.py b/ucloudauth/ufile.py index 9744494..da23915 100644 --- a/ucloudauth/ufile.py +++ b/ucloudauth/ufile.py @@ -123,7 +123,7 @@ def gen_str_to_sign(self, req): str_to_sign = "\n".join([ req.method, req.headers.get("content-md5", ""), - req.headers["content-type"], + req.headers.get("content-type", ""), req.headers.get("date", self._expires), canonicalized_headers + canonicalized_resource ]) @@ -137,7 +137,9 @@ def fill_all_headers(self, req): if content_type is None: content_type = self.DEFAULT_TYPE logger.warn("can not determine mime-type for {0}".format(url.path)) - req.headers.setdefault("content-type", content_type) + if self._expires is None: + # sign with url, no content-type for url + req.headers.setdefault("content-type", content_type) if ( req.body is not None