File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ )
2327from ._compat import cached_property
2428from ._version import __version__
2529from ._streaming import Stream as Stream , AsyncStream as AsyncStream
@@ -96,6 +100,15 @@ def __init__(
96100 if base_url is None :
97101 base_url = f"https://api.moderationapi.com/v1"
98102
103+ custom_headers_env = os .environ .get ("MODERATION_API_CUSTOM_HEADERS" )
104+ if custom_headers_env is not None :
105+ parsed : dict [str , str ] = {}
106+ for line in custom_headers_env .split ("\n " ):
107+ colon = line .find (":" )
108+ if colon >= 0 :
109+ parsed [line [:colon ].strip ()] = line [colon + 1 :].strip ()
110+ default_headers = {** parsed , ** (default_headers if is_mapping_t (default_headers ) else {})}
111+
99112 super ().__init__ (
100113 version = __version__ ,
101114 base_url = base_url ,
@@ -306,6 +319,15 @@ def __init__(
306319 if base_url is None :
307320 base_url = f"https://api.moderationapi.com/v1"
308321
322+ custom_headers_env = os .environ .get ("MODERATION_API_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 ,
You can’t perform that action at this time.
0 commit comments