Skip to content

Commit 6841539

Browse files
feat: support setting headers via env
1 parent d086e7f commit 6841539

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/beeper_desktop_api/_client.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
)
2727
from ._utils import (
2828
is_given,
29+
is_mapping_t,
2930
maybe_transform,
3031
get_async_library,
3132
async_maybe_transform,
@@ -113,6 +114,15 @@ def __init__(
113114
if base_url is None:
114115
base_url = f"http://localhost:23373"
115116

117+
custom_headers_env = os.environ.get("BEEPER_DESKTOP_CUSTOM_HEADERS")
118+
if custom_headers_env is not None:
119+
parsed: dict[str, str] = {}
120+
for line in custom_headers_env.split("\n"):
121+
colon = line.find(":")
122+
if colon >= 0:
123+
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
124+
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}
125+
116126
super().__init__(
117127
version=__version__,
118128
base_url=base_url,
@@ -408,6 +418,15 @@ def __init__(
408418
if base_url is None:
409419
base_url = f"http://localhost:23373"
410420

421+
custom_headers_env = os.environ.get("BEEPER_DESKTOP_CUSTOM_HEADERS")
422+
if custom_headers_env is not None:
423+
parsed: dict[str, str] = {}
424+
for line in custom_headers_env.split("\n"):
425+
colon = line.find(":")
426+
if colon >= 0:
427+
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
428+
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}
429+
411430
super().__init__(
412431
version=__version__,
413432
base_url=base_url,

0 commit comments

Comments
 (0)