Add client header option to requests (#61)

* Add header option

* Add header option

* Add unit test for headers

* Add client header

* Remove environ for HEADER

environ does not support dictionaries, so HEADER can't be passed.
This commit is contained in:
mazhead
2019-03-31 10:18:48 +02:00
committed by mtakaki
parent eae51967c4
commit 3af53ce9b6
4 changed files with 34 additions and 6 deletions

View File

@@ -97,6 +97,7 @@ class Configuration(object):
self.endpoint_url = os.environ.get('ENDPOINT_URL') or self.data['endpoint']['url']
self.endpoint_url = normalize_url(self.endpoint_url)
self.endpoint_timeout = os.environ.get('ENDPOINT_TIMEOUT') or self.data['endpoint'].get('timeout') or 1
self.endpoint_header = self.data['endpoint'].get('header') or None
self.allowed_fails = os.environ.get('ALLOWED_FAILS') or self.data['endpoint'].get('allowed_fails') or 0
self.api_url = os.environ.get('CACHET_API_URL') or self.data['cachet']['api_url']
@@ -172,7 +173,10 @@ class Configuration(object):
according to the expectation results.
"""
try:
self.request = requests.request(self.endpoint_method, self.endpoint_url, timeout=self.endpoint_timeout)
if self.endpoint_header is not None:
self.request = requests.request(self.endpoint_method, self.endpoint_url, timeout=self.endpoint_timeout, headers=self.endpoint_header)
else:
self.request = requests.request(self.endpoint_method, self.endpoint_url, timeout=self.endpoint_timeout)
self.current_timestamp = int(time.time())
except requests.ConnectionError:
self.message = 'The URL is unreachable: %s %s' % (self.endpoint_method, self.endpoint_url)