summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimur Alperovich <timuralp@swiftstack.com>2018-03-05 17:33:22 -0800
committerTimur Alperovich <timuralp@swiftstack.com>2018-03-05 17:33:22 -0800
commita36c3cfda1c243273fcd11b9e123aca877869244 (patch)
tree18ef07bf58f05bc3a830c05711736a720ee4ad70
parent73f0259dbc847eee027f76a9e867fe8c53bf9918 (diff)
downloadpython-swiftclient-a36c3cfda1c243273fcd11b9e123aca877869244.tar.gz
Add a query_string option to head_object().
Submitting a path parameter with a HEAD request on an object can be useful if one is trying to find out information about an SLO/DLO without retrieving the manifest. Change-Id: I39efd098e72bd31de271ac51d4d75381929c9638
-rw-r--r--swiftclient/client.py9
-rw-r--r--tests/unit/test_swiftclient.py15
2 files changed, 19 insertions, 5 deletions
diff --git a/swiftclient/client.py b/swiftclient/client.py
index 7db75f0..60abbd8 100644
--- a/swiftclient/client.py
+++ b/swiftclient/client.py
@@ -1188,7 +1188,7 @@ def get_object(url, token, container, name, http_conn=None,
def head_object(url, token, container, name, http_conn=None,
- service_token=None, headers=None):
+ service_token=None, headers=None, query_string=None):
"""
Get object info
@@ -1209,6 +1209,8 @@ def head_object(url, token, container, name, http_conn=None,
else:
parsed, conn = http_connection(url)
path = '%s/%s/%s' % (parsed.path, quote(container), quote(name))
+ if query_string:
+ path += '?' + query_string
if headers:
headers = dict(headers)
else:
@@ -1785,9 +1787,10 @@ class Connection(object):
query_string=query_string,
headers=headers)
- def head_object(self, container, obj, headers=None):
+ def head_object(self, container, obj, headers=None, query_string=None):
"""Wrapper for :func:`head_object`"""
- return self._retry(None, head_object, container, obj, headers=headers)
+ return self._retry(None, head_object, container, obj, headers=headers,
+ query_string=query_string)
def get_object(self, container, obj, resp_chunk_size=None,
query_string=None, response_dict=None, headers=None):
diff --git a/tests/unit/test_swiftclient.py b/tests/unit/test_swiftclient.py
index 3de5f02..7b8628b 100644
--- a/tests/unit/test_swiftclient.py
+++ b/tests/unit/test_swiftclient.py
@@ -1180,6 +1180,16 @@ class TestHeadObject(MockHttpTest):
}),
])
+ def test_query_string(self):
+ c.http_connection = self.fake_http_connection(204)
+ conn = c.http_connection('http://www.test.com')
+ query_string = 'foo=bar'
+ c.head_object('url_is_irrelevant', 'token', 'container', 'key',
+ http_conn=conn, query_string=query_string)
+ self.assertRequests([
+ ('HEAD', '/container/key?foo=bar', '', {'x-auth-token': 'token'})
+ ])
+
class TestPutObject(MockHttpTest):
@@ -2459,16 +2469,17 @@ class TestConnection(MockHttpTest):
def test_head_object(self):
headers = {'X-Favourite-Pet': 'Aardvark'}
+ query_string = 'foo=bar'
with mock.patch('swiftclient.client.http_connection',
self.fake_http_connection(200)):
with mock.patch('swiftclient.client.get_auth',
lambda *a, **k: ('http://url:8080/v1/a', 'token')):
conn = c.Connection()
conn.head_object('c1', 'o1',
- headers=headers)
+ headers=headers, query_string=query_string)
self.assertEqual(1, len(self.request_log), self.request_log)
self.assertRequests([
- ('HEAD', '/v1/a/c1/o1', '', {
+ ('HEAD', '/v1/a/c1/o1?foo=bar', '', {
'x-auth-token': 'token',
'X-Favourite-Pet': 'Aardvark',
}),