Skip to content

Commit 3311032

Browse files
committed
feat: add additional headers to config and pass them through the request
1 parent df75f68 commit 3311032

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/typesense/configuration.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ class ConfigDict(typing.TypedDict):
7474
master_node (typing.Union[str, NodeConfigDict], deprecated): A dictionary or
7575
URL that represents the master node.
7676
77+
additional_headers (dict): Additional headers to include in the request.
78+
7779
read_replica_nodes (list[typing.Union[str, NodeConfigDict]], deprecated): A list of
7880
dictionaries or URLs that represent the read replica nodes.
7981
"""
@@ -87,6 +89,7 @@ class ConfigDict(typing.TypedDict):
8789
verify: typing.NotRequired[bool]
8890
timeout_seconds: typing.NotRequired[int] # deprecated
8991
master_node: typing.NotRequired[typing.Union[str, NodeConfigDict]] # deprecated
92+
additional_headers: typing.NotRequired[typing.Dict[str, str]]
9093
read_replica_nodes: typing.NotRequired[
9194
typing.List[typing.Union[str, NodeConfigDict]]
9295
] # deprecated
@@ -213,6 +216,7 @@ def __init__(
213216
60,
214217
)
215218
self.verify = config_dict.get("verify", True)
219+
self.additional_headers = config_dict.get("additional_headers", {})
216220

217221
def _handle_nearest_node(
218222
self,

src/typesense/request_handler.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,11 @@ def make_request(
204204
Raises:
205205
TypesenseClientError: If the API returns an error response.
206206
"""
207-
headers = {self.api_key_header_name: self.config.api_key}
207+
headers = {
208+
self.api_key_header_name: self.config.api_key,
209+
}
210+
headers.update(self.config.additional_headers)
211+
208212
kwargs.setdefault("headers", {}).update(headers)
209213
kwargs.setdefault("timeout", self.config.connection_timeout_seconds)
210214
kwargs.setdefault("verify", self.config.verify)

0 commit comments

Comments
 (0)