Skip to content

Commit fb16646

Browse files
feat: support setting headers via env
1 parent 240032d commit fb16646

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

src/openlayer/_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
@@ -95,6 +99,15 @@ def __init__(
9599
if base_url is None:
96100
base_url = f"https://api.openlayer.com/v1"
97101

102+
custom_headers_env = os.environ.get("OPENLAYER_CUSTOM_HEADERS")
103+
if custom_headers_env is not None:
104+
parsed: dict[str, str] = {}
105+
for line in custom_headers_env.split("\n"):
106+
colon = line.find(":")
107+
if colon >= 0:
108+
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
109+
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}
110+
98111
super().__init__(
99112
version=__version__,
100113
base_url=base_url,
@@ -306,6 +319,15 @@ def __init__(
306319
if base_url is None:
307320
base_url = f"https://api.openlayer.com/v1"
308321

322+
custom_headers_env = os.environ.get("OPENLAYER_CUSTOM_HEADERS")
323+
if custom_headers_env is not None:
324+
parsed: dict[str, str] = {}
325+
for line in custom_headers_env.split("\n"):
326+
colon = line.find(":")
327+
if colon >= 0:
328+
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
329+
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}
330+
309331
super().__init__(
310332
version=__version__,
311333
base_url=base_url,

0 commit comments

Comments
 (0)