Skip to content

Commit 273abbc

Browse files
feat: support setting headers via env
1 parent 7ad94ce commit 273abbc

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

src/mobilerun_sdk/_client.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
RequestOptions,
2121
not_given,
2222
)
23-
from ._utils import is_given, get_async_library
23+
from ._utils import (
24+
is_given,
25+
is_mapping_t,
26+
get_async_library,
27+
)
2428
from ._compat import cached_property
2529
from ._version import __version__
2630
from ._streaming import Stream as Stream, AsyncStream as AsyncStream
@@ -96,6 +100,15 @@ def __init__(
96100
if base_url is None:
97101
base_url = f"https://api.mobilerun.ai/v1"
98102

103+
custom_headers_env = os.environ.get("MOBILERUN_CUSTOM_HEADERS")
104+
if custom_headers_env is not None:
105+
parsed: dict[str, str] = {}
106+
for line in custom_headers_env.split("\n"):
107+
colon = line.find(":")
108+
if colon >= 0:
109+
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
110+
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}
111+
99112
super().__init__(
100113
version=__version__,
101114
base_url=base_url,
@@ -334,6 +347,15 @@ def __init__(
334347
if base_url is None:
335348
base_url = f"https://api.mobilerun.ai/v1"
336349

350+
custom_headers_env = os.environ.get("MOBILERUN_CUSTOM_HEADERS")
351+
if custom_headers_env is not None:
352+
parsed: dict[str, str] = {}
353+
for line in custom_headers_env.split("\n"):
354+
colon = line.find(":")
355+
if colon >= 0:
356+
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
357+
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}
358+
337359
super().__init__(
338360
version=__version__,
339361
base_url=base_url,

0 commit comments

Comments
 (0)