From b040de1d88a267b4e4289d505132336bb54f5cfb Mon Sep 17 00:00:00 2001 From: kristiankralovic Date: Mon, 9 Dec 2024 11:07:29 +0100 Subject: [PATCH] Allow additional headers in requests --- mergadoapiclient/client.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mergadoapiclient/client.py b/mergadoapiclient/client.py index 5e70218..730feb6 100644 --- a/mergadoapiclient/client.py +++ b/mergadoapiclient/client.py @@ -42,11 +42,12 @@ class BaseClient(object): def __init__(self, client_id, client_secret, grant_type=None, storage_class=config.TOKEN_STORAGE_CLASS, token_uri=config.TOKEN_URI, api_uri=config.MERGADO_API_URI, - retry_status_list=(500, 502, 503, 504), tries=3): + retry_status_list=(500, 502, 503, 504), tries=3, headers=None): self.client_id = client_id self.client_secret = client_secret self.grant_type = grant_type + self.headers = headers or {} self.TokenStorage = _class_from_string(storage_class) self.storage = self.TokenStorage() @@ -84,11 +85,18 @@ def get_url(self, path): path = path[1:] return urljoin(self.api_uri, path) + def get_headers(self): + headers = { + **self._token_headers, + **self.headers + } + return headers + def request(self, method, path, **options): def make_request(): return http.request( method, self.get_url(path), - headers=self._token_headers, **options) + headers=self.get_headers(), **options) response = retry_request( make_request, self.retry_status_list, self.tries)