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
This commit is contained in:
parent
73f0259dbc
commit
a36c3cfda1
@ -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):
|
||||
|
@ -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',
|
||||
}),
|
||||
|
Loading…
x
Reference in New Issue
Block a user