Skip to content

Commit 095bd46

Browse files
feat: support setting headers via env
1 parent 27c24cd commit 095bd46

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/landingai_ade/_client.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
)
4040
from ._utils import (
4141
is_given,
42+
is_mapping_t,
4243
extract_files,
4344
maybe_transform,
4445
get_async_library,
@@ -200,6 +201,15 @@ def __init__(
200201
except KeyError as exc:
201202
raise ValueError(f"Unknown environment: {environment}") from exc
202203

204+
custom_headers_env = os.environ.get("LANDINGAI_ADE_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+
203213
super().__init__(
204214
version=__version__,
205215
base_url=base_url,
@@ -887,6 +897,15 @@ def __init__(
887897
except KeyError as exc:
888898
raise ValueError(f"Unknown environment: {environment}") from exc
889899

900+
custom_headers_env = os.environ.get("LANDINGAI_ADE_CUSTOM_HEADERS")
901+
if custom_headers_env is not None:
902+
parsed: dict[str, str] = {}
903+
for line in custom_headers_env.split("\n"):
904+
colon = line.find(":")
905+
if colon >= 0:
906+
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
907+
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}
908+
890909
super().__init__(
891910
version=__version__,
892911
base_url=base_url,

0 commit comments

Comments
 (0)