Skip to content

Commit 38c7369

Browse files
feat: support setting headers via env
1 parent a78b44f commit 38c7369

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

src/onebusaway/_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
@@ -151,6 +155,15 @@ def __init__(
151155
if base_url is None:
152156
base_url = f"https://api.pugetsound.onebusaway.org"
153157

158+
custom_headers_env = os.environ.get("ONEBUSAWAY_SDK_CUSTOM_HEADERS")
159+
if custom_headers_env is not None:
160+
parsed: dict[str, str] = {}
161+
for line in custom_headers_env.split("\n"):
162+
colon = line.find(":")
163+
if colon >= 0:
164+
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
165+
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}
166+
154167
super().__init__(
155168
version=__version__,
156169
base_url=base_url,
@@ -504,6 +517,15 @@ def __init__(
504517
if base_url is None:
505518
base_url = f"https://api.pugetsound.onebusaway.org"
506519

520+
custom_headers_env = os.environ.get("ONEBUSAWAY_SDK_CUSTOM_HEADERS")
521+
if custom_headers_env is not None:
522+
parsed: dict[str, str] = {}
523+
for line in custom_headers_env.split("\n"):
524+
colon = line.find(":")
525+
if colon >= 0:
526+
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
527+
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}
528+
507529
super().__init__(
508530
version=__version__,
509531
base_url=base_url,

0 commit comments

Comments
 (0)