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/f7ef3c43 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/f7ef3c43 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/f7ef3c43 Branch: refs/heads/trunk Commit: f7ef3c430aa41ba0e53dde014bf3ac410c9b0e8c Parents: 20d9770 Author: Tomaz Muraus <[email protected]> Authored: Sun Oct 19 10:33:38 2014 +0800 Committer: Eric Johnson <[email protected]> Committed: Tue Oct 21 16:12:04 2014 +0000 ---------------------------------------------------------------------- libcloud/utils/connection.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/f7ef3c43/libcloud/utils/connection.py ---------------------------------------------------------------------- diff --git a/libcloud/utils/connection.py b/libcloud/utils/connection.py index f507ad3..1591c64 100644 --- a/libcloud/utils/connection.py +++ b/libcloud/utils/connection.py @@ -21,7 +21,7 @@ __all__ = [ ] -def get_response_object(url, headers=None): +def get_response_object(url, method='GET', headers=None): """ Utility function which uses libcloud's connection class to issue an HTTP request. @@ -29,7 +29,10 @@ def get_response_object(url, headers=None): :param url: URL to send the request to. :type url: ``str`` - :param headers: Custom request headers. + :param method: HTTP method. + :type method: ``str`` + + :param headers: Optional request headers. :type headers: ``dict`` :return: Response object. @@ -39,7 +42,10 @@ def get_response_object(url, headers=None): 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, headers=headers) + response = con.request(action=parsed_url.path, params=parsed_qs, + headers=headers, method=method) return response
