Skip to content

Commit e3efcee

Browse files
feat: support setting headers via env
1 parent f952a4d commit e3efcee

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

src/finch/_client.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121
RequestOptions,
2222
not_given,
2323
)
24-
from ._utils import is_given, get_async_library
24+
from ._utils import (
25+
is_given,
26+
is_mapping_t,
27+
get_async_library,
28+
)
2529
from ._compat import cached_property
2630
from ._models import SecurityOptions
2731
from ._version import __version__
@@ -118,6 +122,15 @@ def __init__(
118122
if base_url is None:
119123
base_url = f"https://api.tryfinch.com"
120124

125+
custom_headers_env = os.environ.get("FINCH_CUSTOM_HEADERS")
126+
if custom_headers_env is not None:
127+
parsed: dict[str, str] = {}
128+
for line in custom_headers_env.split("\n"):
129+
colon = line.find(":")
130+
if colon >= 0:
131+
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
132+
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}
133+
121134
super().__init__(
122135
version=__version__,
123136
base_url=base_url,
@@ -460,6 +473,15 @@ def __init__(
460473
if base_url is None:
461474
base_url = f"https://api.tryfinch.com"
462475

476+
custom_headers_env = os.environ.get("FINCH_CUSTOM_HEADERS")
477+
if custom_headers_env is not None:
478+
parsed: dict[str, str] = {}
479+
for line in custom_headers_env.split("\n"):
480+
colon = line.find(":")
481+
if colon >= 0:
482+
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
483+
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}
484+
463485
super().__init__(
464486
version=__version__,
465487
base_url=base_url,

0 commit comments

Comments
 (0)