Cast header value as str in canonical_headers Type of header value may be other than a str, such as int. e.g. Value of content-lengh when POST/PUT
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/e4f5fbfb Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/e4f5fbfb Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/e4f5fbfb Branch: refs/heads/trunk Commit: e4f5fbfb286b481d46468dbb29a0a283a6eb5da0 Parents: cde8824 Author: Geunwoo Shin <[email protected]> Authored: Wed Jan 27 23:46:34 2016 +0900 Committer: anthony-shaw <[email protected]> Committed: Tue Feb 9 15:12:48 2016 +1100 ---------------------------------------------------------------------- libcloud/common/aws.py | 2 +- libcloud/test/common/test_aws.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/e4f5fbfb/libcloud/common/aws.py ---------------------------------------------------------------------- diff --git a/libcloud/common/aws.py b/libcloud/common/aws.py index 7838ee1..e0a673a 100644 --- a/libcloud/common/aws.py +++ b/libcloud/common/aws.py @@ -315,7 +315,7 @@ class AWSRequestSignerAlgorithmV4(AWSRequestSigner): return ';'.join([k.lower() for k in sorted(headers.keys())]) def _get_canonical_headers(self, headers): - return '\n'.join([':'.join([k.lower(), v.strip()]) + return '\n'.join([':'.join([k.lower(), str(v).strip()]) for k, v in sorted(headers.items())]) + '\n' def _get_payload_hash(self, method, data=None): http://git-wip-us.apache.org/repos/asf/libcloud/blob/e4f5fbfb/libcloud/test/common/test_aws.py ---------------------------------------------------------------------- diff --git a/libcloud/test/common/test_aws.py b/libcloud/test/common/test_aws.py index bfa81fe..a93b9e7 100644 --- a/libcloud/test/common/test_aws.py +++ b/libcloud/test/common/test_aws.py @@ -191,6 +191,15 @@ class AWSRequestSignerAlgorithmV4TestCase(LibcloudTestCase): }), 'Action=DescribeInstances&Filter.1.Name=state&Version=2013-10-15') + def test_get_canonical_headers_allow_numeric_header_value(self): + headers = { + 'Accept-Encoding': 'gzip,deflate', + 'Content-Length': 314 + } + self.assertEqual(self.signer._get_canonical_headers(headers), + 'accept-encoding:gzip,deflate\n' + 'content-length:314\n') + def test_get_request_params_allows_integers_as_value(self): self.assertEqual(self.signer._get_request_params({'Action': 'DescribeInstances', 'Port': 22}), 'Action=DescribeInstances&Port=22')
