Skip to content

Commit 182af02

Browse files
feat: support setting headers via env
1 parent 2c9207c commit 182af02

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

src/unify/_client.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919
RequestOptions,
2020
not_given,
2121
)
22-
from ._utils import is_given, get_async_library
22+
from ._utils import (
23+
is_given,
24+
is_mapping_t,
25+
get_async_library,
26+
)
2327
from ._compat import cached_property
2428
from ._models import SecurityOptions
2529
from ._version import __version__
@@ -82,6 +86,15 @@ def __init__(
8286
if base_url is None:
8387
base_url = f"https://api.unifygtm.com"
8488

89+
custom_headers_env = os.environ.get("UNIFY_CUSTOM_HEADERS")
90+
if custom_headers_env is not None:
91+
parsed: dict[str, str] = {}
92+
for line in custom_headers_env.split("\n"):
93+
colon = line.find(":")
94+
if colon >= 0:
95+
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
96+
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}
97+
8598
super().__init__(
8699
version=__version__,
87100
base_url=base_url,
@@ -261,6 +274,15 @@ def __init__(
261274
if base_url is None:
262275
base_url = f"https://api.unifygtm.com"
263276

277+
custom_headers_env = os.environ.get("UNIFY_CUSTOM_HEADERS")
278+
if custom_headers_env is not None:
279+
parsed: dict[str, str] = {}
280+
for line in custom_headers_env.split("\n"):
281+
colon = line.find(":")
282+
if colon >= 0:
283+
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
284+
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}
285+
264286
super().__init__(
265287
version=__version__,
266288
base_url=base_url,

0 commit comments

Comments
 (0)