From 6efeab60d93688be2663ec68d5f65911819713d4 Mon Sep 17 00:00:00 2001 From: FUJITA Tomonori Date: Mon, 11 Jul 2011 20:17:58 +0900 Subject: [PATCH] s3api: fix canonical_string for Date and X-Amz-Date header handling canonical_string needs to reset the Date header if it sees the X-Amz-Date header. --- swift/common/middleware/swift3.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/swift/common/middleware/swift3.py b/swift/common/middleware/swift3.py index df1ca3f755..95952bc3eb 100644 --- a/swift/common/middleware/swift3.py +++ b/swift/common/middleware/swift3.py @@ -128,13 +128,23 @@ def canonical_string(req): """ Canonicalize a request to a token that can be signed. """ + amz_headers = {} + buf = "%s\n%s\n%s\n" % (req.method, req.headers.get('Content-MD5', ''), req.headers.get('Content-Type') or '') - if 'Date' in req.headers: - buf += "%s\n" % req.headers['Date'] + for amz_header in sorted((key.lower() for key in req.headers if key.lower().startswith('x-amz-'))): - buf += "%s:%s\n" % (amz_header, req.headers[amz_header]) + amz_headers[amz_header] = req.headers[amz_header] + + if 'x-amz-date' in amz_headers: + buf += "\n" + elif 'Date' in req.headers: + buf += "%s\n" % req.headers['Date'] + + for k in sorted(key.lower() for key in amz_headers): + buf += "%s:%s\n" % (k, amz_headers[k]) + path = req.path_qs if '?' in path: path, args = path.split('?', 1)