Skip to content

Commit 759b6e2

Browse files
feat: support setting headers via env
1 parent 8e94d66 commit 759b6e2

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

src/lithic/_client.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@
2222
RequestOptions,
2323
not_given,
2424
)
25-
from ._utils import is_given, get_async_library
25+
from ._utils import (
26+
is_given,
27+
is_mapping_t,
28+
get_async_library,
29+
)
2630
from ._compat import cached_property
2731
from ._version import __version__
2832
from ._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
@@ -197,6 +201,15 @@ def __init__(
197201
except KeyError as exc:
198202
raise ValueError(f"Unknown environment: {environment}") from exc
199203

204+
custom_headers_env = os.environ.get("LITHIC_CUSTOM_HEADERS")
205+
if custom_headers_env is not None:
206+
parsed: dict[str, str] = {}
207+
for line in custom_headers_env.split("\n"):
208+
colon = line.find(":")
209+
if colon >= 0:
210+
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
211+
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}
212+
200213
super().__init__(
201214
version=__version__,
202215
base_url=base_url,
@@ -612,6 +625,15 @@ def __init__(
612625
except KeyError as exc:
613626
raise ValueError(f"Unknown environment: {environment}") from exc
614627

628+
custom_headers_env = os.environ.get("LITHIC_CUSTOM_HEADERS")
629+
if custom_headers_env is not None:
630+
parsed: dict[str, str] = {}
631+
for line in custom_headers_env.split("\n"):
632+
colon = line.find(":")
633+
if colon >= 0:
634+
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
635+
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}
636+
615637
super().__init__(
616638
version=__version__,
617639
base_url=base_url,

0 commit comments

Comments
 (0)