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
This commit is contained in:
Honza Král
2018-01-01 15:42:46 +01:00
parent 2dce4c0720
commit a023bddb4d
+4 -3
View File
@@ -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: