diff --git a/astakosclient/astakosclient/__init__.py b/astakosclient/astakosclient/__init__.py index 16380405c..efaceea01 100644 --- a/astakosclient/astakosclient/__init__.py +++ b/astakosclient/astakosclient/__init__.py @@ -66,8 +66,8 @@ class AstakosClient(object): # Too many arguments. pylint: disable-msg=R0913 # Too many local variables. pylint: disable-msg=R0914 # Too many statements. pylint: disable-msg=R0915 - def __init__(self, token, auth_url, - retry=0, use_pool=False, pool_size=8, logger=None): + def __init__(self, token, auth_url, retry=0, use_pool=False, pool_size=8, + logger=None, headers=None): """Initialize AstakosClient Class Keyword arguments: @@ -107,6 +107,10 @@ def __init__(self, token, auth_url, self.astakos_base_url = parsed_auth_url.netloc self.scheme = parsed_auth_url.scheme self.conn_class = conn_class + if headers is not None: + self.headers = copy(headers) + else: + self.headers = None # Initialize astakos api prefixes # API urls under auth_url @@ -250,9 +254,15 @@ def _call_astakos(self, request_path, headers=None, method, request_path, hashed_token.hexdigest(), headers, body if log_body else "(not logged)") + if self.headers: + request_headers = copy(self.headers) + else: + request_headers = {} + + if headers is not None: + request_headers.update(headers) + # Check Input - if headers is None: - headers = {} if body is None: body = {} # Initialize log_request and log_response attributes @@ -261,7 +271,7 @@ def _call_astakos(self, request_path, headers=None, # Build request's header and body kwargs = {} - kwargs['headers'] = copy(headers) + kwargs['headers'] = request_headers kwargs['headers']['X-Auth-Token'] = self.token if body: kwargs['body'] = copy(body)