Skip to content

Commit e22462b

Browse files
feat: support setting headers via env
1 parent 4d33037 commit e22462b

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

src/knockapi/_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 ._version import __version__
2529
from ._streaming import Stream as Stream, AsyncStream as AsyncStream
@@ -113,6 +117,15 @@ def __init__(
113117
if base_url is None:
114118
base_url = f"https://api.knock.app"
115119

120+
custom_headers_env = os.environ.get("KNOCK_CUSTOM_HEADERS")
121+
if custom_headers_env is not None:
122+
parsed: dict[str, str] = {}
123+
for line in custom_headers_env.split("\n"):
124+
colon = line.find(":")
125+
if colon >= 0:
126+
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
127+
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}
128+
116129
super().__init__(
117130
version=__version__,
118131
base_url=base_url,
@@ -388,6 +401,15 @@ def __init__(
388401
if base_url is None:
389402
base_url = f"https://api.knock.app"
390403

404+
custom_headers_env = os.environ.get("KNOCK_CUSTOM_HEADERS")
405+
if custom_headers_env is not None:
406+
parsed: dict[str, str] = {}
407+
for line in custom_headers_env.split("\n"):
408+
colon = line.find(":")
409+
if colon >= 0:
410+
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
411+
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}
412+
391413
super().__init__(
392414
version=__version__,
393415
base_url=base_url,

0 commit comments

Comments
 (0)