Skip to content

Commit ec173f7

Browse files
author
Shakeel Mohamed
committed
Mild refactor of index.attach() headers
1 parent 874c1ab commit ec173f7

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

splunklib/client.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,19 +1900,22 @@ def attach(self, host=None, source=None, sourcetype=None):
19001900
if sourcetype is not None: args['sourcetype'] = sourcetype
19011901
path = UrlEncoded(PATH_RECEIVERS_STREAM + "?" + urllib.urlencode(args), skip_encode=True)
19021902

1903+
cookie_or_auth_header = "Authorization: %s\r\n" % self.service.token
1904+
1905+
# If we have a cookie, use it instead of "Authorization: ..."
1906+
if self.service.cookie is not _NoAuthenticationToken:
1907+
cookie_or_auth_header = "Cookie: %s\r\n" % self.service.cookie
1908+
19031909
# Since we need to stream to the index connection, we have to keep
19041910
# the connection open and use the Splunk extension headers to note
19051911
# the input mode
19061912
sock = self.service.connect()
19071913
headers = ["POST %s HTTP/1.1\r\n" % self.service._abspath(path),
19081914
"Host: %s:%s\r\n" % (self.service.host, int(self.service.port)),
19091915
"Accept-Encoding: identity\r\n",
1910-
"Authorization: %s\r\n" % self.service.token,
1916+
cookie_or_auth_header,
19111917
"X-Splunk-Input-Mode: Streaming\r\n",
19121918
"\r\n"]
1913-
# If we have a cookie, use it instead of "Authorization: ..."
1914-
if self.service.cookie is not _NoAuthenticationToken:
1915-
headers[3] = "Cookie: %s\r\n" % self.service.cookie
19161919

19171920
for h in headers:
19181921
sock.write(h)

0 commit comments

Comments
 (0)