Skip to content

Commit 601c6ec

Browse files
committed
chore(internal): add empty request preparation method (#13)
1 parent d2610d9 commit 601c6ec

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/finch/_base_client.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,15 @@ def _build_headers(self, options: FinalRequestOptions) -> httpx.Headers:
482482

483483
return headers
484484

485+
def _prepare_request(self, request: httpx.Request) -> None:
486+
"""This method is used as a callback for mutating the `Request` object
487+
after it has been constructed.
488+
489+
This is useful for cases where you want to add certain headers based off of
490+
the request properties, e.g. `url`, `method` etc.
491+
"""
492+
return None
493+
485494
def _build_request(
486495
self,
487496
options: FinalRequestOptions,
@@ -519,7 +528,7 @@ def _build_request(
519528
kwargs["data"] = self._serialize_multipartform(json_data)
520529

521530
# TODO: report this error to httpx
522-
return self._client.build_request( # pyright: ignore[reportUnknownMemberType]
531+
request = self._client.build_request( # pyright: ignore[reportUnknownMemberType]
523532
headers=headers,
524533
timeout=self.timeout if isinstance(options.timeout, NotGiven) else options.timeout,
525534
method=options.method,
@@ -533,6 +542,8 @@ def _build_request(
533542
files=options.files,
534543
**kwargs,
535544
)
545+
self._prepare_request(request)
546+
return request
536547

537548
def _serialize_multipartform(self, data: Mapping[object, object]) -> dict[str, object]:
538549
items = self.qs.stringify_items(

0 commit comments

Comments
 (0)