diff options
author | Stanislav Vitkovskiy <stas.vitkovsky@gmail.com> | 2013-07-27 17:06:28 +1000 |
---|---|---|
committer | Stanislav Vitkovskiy <stas.vitkovsky@gmail.com> | 2013-07-29 22:53:13 +1000 |
commit | d34f12614820416aebe5e91eab9726b556d1f973 (patch) | |
tree | 7f98963b8d620c54b32f5d850ad09d2933ced7d6 /swiftclient/client.py | |
parent | 5d9c6f845cc98da720fea7e2343fdbb0db9a42a5 (diff) | |
download | python-swiftclient-d34f12614820416aebe5e91eab9726b556d1f973.tar.gz |
Added headers argument support to get_object()
With this change conditional and range GETs are possible, as
documented in official API guide:
http://docs.openstack.org/api/openstack-object-storage/1.0/content/retrieve-object.html
Change-Id: Ib2ed1c21e8d3f1ed79c0b7e542ee022ee535835c
Diffstat (limited to 'swiftclient/client.py')
-rw-r--r-- | swiftclient/client.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/swiftclient/client.py b/swiftclient/client.py index c9012be..b9b07f2 100644 --- a/swiftclient/client.py +++ b/swiftclient/client.py @@ -747,7 +747,7 @@ def delete_container(url, token, container, http_conn=None, def get_object(url, token, container, name, http_conn=None, resp_chunk_size=None, query_string=None, - response_dict=None): + response_dict=None, headers=None): """ Get an object @@ -764,6 +764,8 @@ def get_object(url, token, container, name, http_conn=None, :param query_string: if set will be appended with '?' to generated path :param response_dict: an optional dictionary into which to place the response - status, reason and headers + :param headers: an optional dictionary with additional headers to include + in the request :returns: a tuple of (response headers, the object's contents) The response headers will be a dict and all header names will be lowercase. :raises ClientException: HTTP GET request failed @@ -776,7 +778,8 @@ def get_object(url, token, container, name, http_conn=None, if query_string: path += '?' + query_string method = 'GET' - headers = {'X-Auth-Token': token} + headers = headers.copy() if headers else {} + headers['X-Auth-Token'] = token conn.request(method, path, '', headers) resp = conn.getresponse() @@ -1234,12 +1237,12 @@ class Connection(object): return self._retry(None, head_object, container, obj) def get_object(self, container, obj, resp_chunk_size=None, - query_string=None, response_dict=None): + query_string=None, response_dict=None, headers=None): """Wrapper for :func:`get_object`""" return self._retry(None, get_object, container, obj, resp_chunk_size=resp_chunk_size, query_string=query_string, - response_dict=response_dict) + response_dict=response_dict, headers=headers) def put_object(self, container, obj, contents, content_length=None, etag=None, chunk_size=None, content_type=None, |