Skip to content

Commit 25c28b6

Browse files
committed
Simplify Context.post() to no longer accept a dictionary value for custom headers. Document the headers parameter in Context.{post,request}.
1 parent 3c80f84 commit 25c28b6

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

splunklib/binding.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,8 @@ def post(self, path_segment, owner=None, app=None, sharing=None, headers=None, *
610610
:type app: ``string``
611611
:param sharing: The sharing mode of the namespace (optional).
612612
:type sharing: ``string``
613+
:param headers: List of extra HTTP headers to send (optional).
614+
:type headers: ``list`` of 2-tuples.
613615
:param query: All other keyword arguments, which are used as query
614616
parameters.
615617
:type query: ``string``
@@ -644,13 +646,7 @@ def post(self, path_segment, owner=None, app=None, sharing=None, headers=None, *
644646
path = self.authority + self._abspath(path_segment, owner=owner,
645647
app=app, sharing=sharing)
646648
logging.debug("POST request to %s (body: %s)", path, repr(query))
647-
if isinstance(headers, dict):
648-
all_headers = [(k,v) for k,v in headers.iteritems()]
649-
elif isinstance(headers, list):
650-
all_headers = headers
651-
else:
652-
raise ValueError("headers must be a list or dict (found: %s)" % headers)
653-
all_headers += self._auth_headers
649+
all_headers = headers + self._auth_headers
654650
response = self.http.post(path, all_headers, **query)
655651
return response
656652

@@ -673,6 +669,12 @@ def request(self, path_segment, method="GET", headers=None, body="",
673669
*path_segment*.
674670
:param path_segment: A REST path segment.
675671
:type path_segment: ``string``
672+
:param method: The HTTP method to use (optional).
673+
:type method: ``string``
674+
:param headers: List of extra HTTP headers to send (optional).
675+
:type headers: ``list`` of 2-tuples.
676+
:param body: Content of the HTTP request (optional).
677+
:type body: ``string``
676678
:param owner: The owner context of the namespace (optional).
677679
:type owner: ``string``
678680
:param app: The app context of the namespace (optional).

tests/test_binding.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def test_post_with_get_arguments_to_receivers_stream(self):
211211
text = 'Hello, world!'
212212
response = self.context.post(
213213
'/services/receivers/simple',
214-
headers={'x-splunk-input-mode': 'streaming'},
214+
headers=[('x-splunk-input-mode', 'streaming')],
215215
source='sdk', sourcetype='sdk_test',
216216
body=text
217217
)

0 commit comments

Comments
 (0)