Skip to content

Commit c2ea4c0

Browse files
feat: support setting headers via env
1 parent fe539bc commit c2ea4c0

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

src/asktable/_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
@@ -130,6 +134,15 @@ def __init__(
130134
if base_url is None:
131135
base_url = f"https://api.asktable.com"
132136

137+
custom_headers_env = os.environ.get("ASKTABLE_CUSTOM_HEADERS")
138+
if custom_headers_env is not None:
139+
parsed: dict[str, str] = {}
140+
for line in custom_headers_env.split("\n"):
141+
colon = line.find(":")
142+
if colon >= 0:
143+
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
144+
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}
145+
133146
super().__init__(
134147
version=__version__,
135148
base_url=base_url,
@@ -435,6 +448,15 @@ def __init__(
435448
if base_url is None:
436449
base_url = f"https://api.asktable.com"
437450

451+
custom_headers_env = os.environ.get("ASKTABLE_CUSTOM_HEADERS")
452+
if custom_headers_env is not None:
453+
parsed: dict[str, str] = {}
454+
for line in custom_headers_env.split("\n"):
455+
colon = line.find(":")
456+
if colon >= 0:
457+
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
458+
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}
459+
438460
super().__init__(
439461
version=__version__,
440462
base_url=base_url,

0 commit comments

Comments
 (0)