From f47dcd2a312892f6dcdd3cb50a9c38fab588a169 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Wed, 20 Jul 2016 14:27:45 +0200 Subject: [PATCH] Enable global HTTP headers to be sent with every request. --- pillarsdk/api.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pillarsdk/api.py b/pillarsdk/api.py index 6f655cb..79bd288 100644 --- a/pillarsdk/api.py +++ b/pillarsdk/api.py @@ -1,3 +1,4 @@ +import copy import base64 import requests import json @@ -23,6 +24,9 @@ class Api(object): # Global session object to do HTTP requests. requests_session = requests.session() + # HTTP headers that should always be sent with every request. + global_headers = {} + def __init__(self, options=None, **kwargs): """Create API object @@ -158,11 +162,12 @@ class Api(object): """ token = self.get_token() - headers = { + headers = copy.deepcopy(self.global_headers) + headers.update({ # "Content-Type": "application/json", "Accept": "application/json", "User-Agent": self.user_agent - } + }) if token: headers['Authorization'] = (