Skip to content

Commit a023bdd

Browse files
committed
Use provided request headers in urllib3
outside. However, `Urllib3HttpConnection` did not use these headers but only its default ones. With this commit, `Urllib3HttpConnection` will either use the default ones or merge the default headers with the provided ones if there are any. Relates elastic#618
1 parent 2dce4c0 commit a023bdd

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

elasticsearch/connection/http_urllib3.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,11 @@ def perform_request(self, method, url, params=None, body=None, timeout=None, ign
142142
if not isinstance(method, str):
143143
method = method.encode('utf-8')
144144

145+
request_headers = self.headers
145146
if headers:
146-
request_headers = dict(self.headers)
147-
request_headers.update(headers or {})
148-
response = self.pool.urlopen(method, url, body, retries=False, headers=self.headers, **kw)
147+
request_headers = request_headers.copy()
148+
request_headers.update(headers)
149+
response = self.pool.urlopen(method, url, body, retries=False, headers=request_headers, **kw)
149150
duration = time.time() - start
150151
raw_data = response.data.decode('utf-8')
151152
except Exception as e:

0 commit comments

Comments
 (0)