You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2014/10/19 04:44:23 UTC
git commit: Allow users to pass "headers" and "method" argument to
the get_response_object utility method.
Repository: libcloud
Updated Branches:
refs/heads/trunk a38ade584 -> 3cd156c5e
Allow users to pass "headers" and "method" argument to the get_response_object
utility method.
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/3cd156c5
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/3cd156c5
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/3cd156c5
Branch: refs/heads/trunk
Commit: 3cd156c5e1875c4d8f991651892ecf60f8939eb9
Parents: a38ade5
Author: Tomaz Muraus <to...@apache.org>
Authored: Sun Oct 19 10:33:38 2014 +0800
Committer: Tomaz Muraus <to...@apache.org>
Committed: Sun Oct 19 10:33:38 2014 +0800
----------------------------------------------------------------------
libcloud/utils/connection.py | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/3cd156c5/libcloud/utils/connection.py
----------------------------------------------------------------------
diff --git a/libcloud/utils/connection.py b/libcloud/utils/connection.py
index db381a3..1591c64 100644
--- a/libcloud/utils/connection.py
+++ b/libcloud/utils/connection.py
@@ -21,7 +21,7 @@ __all__ = [
]
-def get_response_object(url):
+def get_response_object(url, method='GET', headers=None):
"""
Utility function which uses libcloud's connection class to issue an HTTP
request.
@@ -29,6 +29,12 @@ def get_response_object(url):
:param url: URL to send the request to.
:type url: ``str``
+ :param method: HTTP method.
+ :type method: ``str``
+
+ :param headers: Optional request headers.
+ :type headers: ``dict``
+
:return: Response object.
:rtype: :class:`Response`.
"""
@@ -36,7 +42,10 @@ def get_response_object(url):
parsed_qs = parse_qs(parsed_url.query)
secure = parsed_url.scheme == 'https'
+ headers = headers or {}
+ method = method.upper()
+
con = Connection(secure=secure, host=parsed_url.netloc)
- response = con.request(method='GET', action=parsed_url.path,
- params=parsed_qs)
+ response = con.request(action=parsed_url.path, params=parsed_qs,
+ headers=headers, method=method)
return response