diff --git a/splunklib/binding.py b/splunklib/binding.py index 4a4098df..eafa2f96 100644 --- a/splunklib/binding.py +++ b/splunklib/binding.py @@ -526,23 +526,27 @@ def _auth_headers(self): :returns: A list of 2-tuples containing key and value """ + header = [] if self.has_cookies(): return [("Cookie", _make_cookie_header(list(self.get_cookies().items())))] elif self.basic and (self.username and self.password): token = 'Basic %s' % b64encode(("%s:%s" % (self.username, self.password)).encode('utf-8')).decode('ascii') - return [("Authorization", token)] elif self.bearerToken: token = 'Bearer %s' % self.bearerToken - return [("Authorization", token)] elif self.token is _NoAuthenticationToken: - return [] + token = [] else: # Ensure the token is properly formatted if self.token.startswith('Splunk '): token = self.token else: token = 'Splunk %s' % self.token - return [("Authorization", token)] + if token: + header.append(("Authorization", token)) + if self.get_cookies().__len__() > 0: + header.append("Cookie", _make_cookie_header(self.get_cookies().items())) + + return header def connect(self): """Returns an open connection (socket) to the Splunk instance.