From 3407d737c705a7afedeed0159588ab4433a601f3 Mon Sep 17 00:00:00 2001 From: David Liu Date: Thu, 24 Mar 2016 16:08:19 +0800 Subject: [PATCH] Handle tempurl Content-Disposition header missing from HEAD Content-Disposition headers should make no difference between GET and HEAD according to HTTP rfc. Closes-Bug: #1539805 Change-Id: Ifa41a7cda2f321eb8e36420ede7912ed0a549712 --- swift/common/middleware/tempurl.py | 2 +- test/unit/common/middleware/test_tempurl.py | 25 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/swift/common/middleware/tempurl.py b/swift/common/middleware/tempurl.py index 7fece15b34..234820791c 100644 --- a/swift/common/middleware/tempurl.py +++ b/swift/common/middleware/tempurl.py @@ -400,7 +400,7 @@ class TempURL(object): def _start_response(status, headers, exc_info=None): headers = self._clean_outgoing_headers(headers) - if env['REQUEST_METHOD'] == 'GET' and status[0] == '2': + if env['REQUEST_METHOD'] in ('GET', 'HEAD') and status[0] == '2': # figure out the right value for content-disposition # 1) use the value from the query string # 2) use the value from the object metadata diff --git a/test/unit/common/middleware/test_tempurl.py b/test/unit/common/middleware/test_tempurl.py index d407ba58b1..0fc895f9e2 100644 --- a/test/unit/common/middleware/test_tempurl.py +++ b/test/unit/common/middleware/test_tempurl.py @@ -215,6 +215,31 @@ class TestTempURL(unittest.TestCase): resp = req.get_response(self.tempurl) self.assertEqual(resp.status_int, 200) + def test_head_and_get_headers_match(self): + method = 'HEAD' + expires = int(time() + 86400) + path = '/v1/a/c/o' + key = 'abc' + hmac_body = '%s\n%s\n%s' % (method, expires, path) + sig = hmac.new(key, hmac_body, sha1).hexdigest() + req = self._make_request(path, keys=[key], environ={ + 'REQUEST_METHOD': 'HEAD', + 'QUERY_STRING': 'temp_url_sig=%s&temp_url_expires=%s' + % (sig, expires)}) + self.tempurl.app = FakeApp(iter([('200 Ok', (), '123')])) + resp = req.get_response(self.tempurl) + + get_method = 'GET' + get_hmac_body = '%s\n%s\n%s' % (get_method, expires, path) + get_sig = hmac.new(key, get_hmac_body, sha1).hexdigest() + get_req = self._make_request(path, keys=[key], environ={ + 'REQUEST_METHOD': 'GET', + 'QUERY_STRING': 'temp_url_sig=%s&temp_url_expires=%s' + % (get_sig, expires)}) + self.tempurl.app = FakeApp(iter([('200 Ok', (), '123')])) + get_resp = get_req.get_response(self.tempurl) + self.assertEqual(resp.headers, get_resp.headers) + def test_get_valid_with_filename_and_inline(self): method = 'GET' expires = int(time() + 86400)