From a023bddb4dc572bed41433d211e0e65249ac4cc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Honza=20Kr=C3=A1l?= Date: Mon, 1 Jan 2018 15:42:46 +0100 Subject: [PATCH] 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 #618 --- elasticsearch/connection/http_urllib3.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/elasticsearch/connection/http_urllib3.py b/elasticsearch/connection/http_urllib3.py index 59865e29..e2ae166d 100644 --- a/elasticsearch/connection/http_urllib3.py +++ b/elasticsearch/connection/http_urllib3.py @@ -142,10 +142,11 @@ class Urllib3HttpConnection(Connection): if not isinstance(method, str): method = method.encode('utf-8') + request_headers = self.headers if headers: - request_headers = dict(self.headers) - request_headers.update(headers or {}) - response = self.pool.urlopen(method, url, body, retries=False, headers=self.headers, **kw) + request_headers = request_headers.copy() + request_headers.update(headers) + response = self.pool.urlopen(method, url, body, retries=False, headers=request_headers, **kw) duration = time.time() - start raw_data = response.data.decode('utf-8') except Exception as e: