From e7a631a2b542d34c025260eea37496c7b854164f Mon Sep 17 00:00:00 2001 From: Bill Murrin Date: Tue, 23 Jul 2019 22:55:06 -0400 Subject: [PATCH 1/2] properly add parameters to request based on the method of the request --- splunklib/binding.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/splunklib/binding.py b/splunklib/binding.py index 3fe7c8495..ae732cc90 100644 --- a/splunklib/binding.py +++ b/splunklib/binding.py @@ -754,7 +754,7 @@ def post(self, path_segment, owner=None, app=None, sharing=None, headers=None, * @_authentication @_log_duration - def request(self, path_segment, method="GET", headers=None, body="", + def request(self, path_segment, method="GET", headers=None, body={}, owner=None, app=None, sharing=None): """Issues an arbitrary HTTP request to the REST path segment. @@ -814,13 +814,27 @@ def request(self, path_segment, method="GET", headers=None, body="", path = self.authority \ + self._abspath(path_segment, owner=owner, app=app, sharing=sharing) + all_headers = headers + self.additional_headers + self._auth_headers logging.debug("%s request to %s (headers: %s, body: %s)", method, path, str(all_headers), repr(body)) - response = self.http.request(path, + + if body: + body = _encode(**body) + if method == "GET": + path = path + UrlEncoded('?' + body, skip_encode=True) + response = self.http.request(path, {'method': method, - 'headers': all_headers, - 'body': body}) + 'headers': all_headers}) + else: + response = self.http.request(path, + {'method': method, + 'headers': all_headers, + 'body': body}) + else: + response = self.http.request(path, + {'method': method, + 'headers': all_headers}) return response def login(self): From 19d59c6c63149d68c4893dc7d10f87e5d88a1fb4 Mon Sep 17 00:00:00 2001 From: Bill Murrin Date: Fri, 9 Aug 2019 11:28:39 -0700 Subject: [PATCH 2/2] reduced number of api calls --- splunklib/binding.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/splunklib/binding.py b/splunklib/binding.py index ae732cc90..024b4c190 100644 --- a/splunklib/binding.py +++ b/splunklib/binding.py @@ -821,20 +821,21 @@ def request(self, path_segment, method="GET", headers=None, body={}, if body: body = _encode(**body) + if method == "GET": path = path + UrlEncoded('?' + body, skip_encode=True) - response = self.http.request(path, - {'method': method, - 'headers': all_headers}) + message = {'method': method, + 'headers': all_headers} else: - response = self.http.request(path, - {'method': method, - 'headers': all_headers, - 'body': body}) + message = {'method': method, + 'headers': all_headers, + 'body': body} else: - response = self.http.request(path, - {'method': method, - 'headers': all_headers}) + message = {'method': method, + 'headers': all_headers} + + response = self.http.request(path, message) + return response def login(self):