Skip to content

Commit 39cbf90

Browse files
feat: support setting headers via env
1 parent c89d2b3 commit 39cbf90

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

src/imagekitio/_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 ._version import __version__
2731
from ._streaming import Stream as Stream, AsyncStream as AsyncStream
@@ -128,6 +132,15 @@ def __init__(
128132
if base_url is None:
129133
base_url = f"https://api.imagekit.io"
130134

135+
custom_headers_env = os.environ.get("IMAGE_KIT_CUSTOM_HEADERS")
136+
if custom_headers_env is not None:
137+
parsed: dict[str, str] = {}
138+
for line in custom_headers_env.split("\n"):
139+
colon = line.find(":")
140+
if colon >= 0:
141+
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
142+
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}
143+
131144
super().__init__(
132145
version=__version__,
133146
base_url=base_url,
@@ -396,6 +409,15 @@ def __init__(
396409
if base_url is None:
397410
base_url = f"https://api.imagekit.io"
398411

412+
custom_headers_env = os.environ.get("IMAGE_KIT_CUSTOM_HEADERS")
413+
if custom_headers_env is not None:
414+
parsed: dict[str, str] = {}
415+
for line in custom_headers_env.split("\n"):
416+
colon = line.find(":")
417+
if colon >= 0:
418+
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
419+
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}
420+
399421
super().__init__(
400422
version=__version__,
401423
base_url=base_url,

0 commit comments

Comments
 (0)