Skip to content

Commit 09e16ca

Browse files
lesnik512claude
andcommitted
refactor(client): extract _prepare_request from _request_with_body
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent b7cc53b commit 09e16ca

1 file changed

Lines changed: 66 additions & 6 deletions

File tree

src/httpware/client.py

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def build_request(self, method: str, url: str, **kwargs: typing.Any) -> httpx2.R
228228
"""Delegate request construction to the wrapped httpx2.AsyncClient."""
229229
return self._httpx2_client.build_request(method, url, **kwargs)
230230

231-
async def _request_with_body( # noqa: PLR0913, C901 — mirrors httpx2 per-method signatures; kwargs-forwarding complexity is structural
231+
def _prepare_request( # noqa: PLR0913, C901 — mirrors httpx2 per-method signatures; kwargs-forwarding complexity is structural
232232
self,
233233
method: str,
234234
url: str,
@@ -242,8 +242,7 @@ async def _request_with_body( # noqa: PLR0913, C901 — mirrors httpx2 per-meth
242242
content: typing.Any | None = None,
243243
data: typing.Any | None = None,
244244
files: typing.Any | None = None,
245-
response_model: type[T] | None = None,
246-
) -> httpx2.Response | T:
245+
) -> httpx2.Request:
247246
kwargs: dict[str, typing.Any] = {}
248247
if params is not None:
249248
kwargs["params"] = params
@@ -266,6 +265,37 @@ async def _request_with_body( # noqa: PLR0913, C901 — mirrors httpx2 per-meth
266265
request = self._httpx2_client.build_request(method, url, **kwargs)
267266
if _is_streaming_body_async(content) or _is_streaming_body_async(data) or _is_streaming_body_async(files):
268267
request.extensions[STREAMING_BODY_MARKER] = True
268+
return request
269+
270+
async def _request_with_body( # noqa: PLR0913 — mirrors httpx2 per-method signatures
271+
self,
272+
method: str,
273+
url: str,
274+
*,
275+
params: typing.Any | None = None,
276+
headers: typing.Any | None = None,
277+
cookies: typing.Any | None = None,
278+
timeout: typing.Any = httpx2.USE_CLIENT_DEFAULT,
279+
extensions: typing.Any | None = None,
280+
json: typing.Any | None = None,
281+
content: typing.Any | None = None,
282+
data: typing.Any | None = None,
283+
files: typing.Any | None = None,
284+
response_model: type[T] | None = None,
285+
) -> httpx2.Response | T:
286+
request = self._prepare_request(
287+
method,
288+
url,
289+
params=params,
290+
headers=headers,
291+
cookies=cookies,
292+
timeout=timeout,
293+
extensions=extensions,
294+
json=json,
295+
content=content,
296+
data=data,
297+
files=files,
298+
)
269299
return await self.send(request, response_model=response_model)
270300

271301
@typing.overload
@@ -1003,7 +1033,7 @@ def build_request(self, method: str, url: str, **kwargs: typing.Any) -> httpx2.R
10031033
"""Delegate request construction to the wrapped httpx2.Client."""
10041034
return self._httpx2_client.build_request(method, url, **kwargs)
10051035

1006-
def _request_with_body( # noqa: PLR0913, C901 — mirrors httpx2 per-method signatures; kwargs-forwarding complexity is structural
1036+
def _prepare_request( # noqa: PLR0913, C901 — mirrors httpx2 per-method signatures; kwargs-forwarding complexity is structural
10071037
self,
10081038
method: str,
10091039
url: str,
@@ -1017,8 +1047,7 @@ def _request_with_body( # noqa: PLR0913, C901 — mirrors httpx2 per-method sig
10171047
content: typing.Any | None = None,
10181048
data: typing.Any | None = None,
10191049
files: typing.Any | None = None,
1020-
response_model: type[T] | None = None,
1021-
) -> httpx2.Response | T:
1050+
) -> httpx2.Request:
10221051
kwargs: dict[str, typing.Any] = {}
10231052
if params is not None:
10241053
kwargs["params"] = params
@@ -1041,6 +1070,37 @@ def _request_with_body( # noqa: PLR0913, C901 — mirrors httpx2 per-method sig
10411070
request = self._httpx2_client.build_request(method, url, **kwargs)
10421071
if _is_streaming_body_sync(content) or _is_streaming_body_sync(data) or _is_streaming_body_sync(files):
10431072
request.extensions[STREAMING_BODY_MARKER] = True
1073+
return request
1074+
1075+
def _request_with_body( # noqa: PLR0913 — mirrors httpx2 per-method signatures
1076+
self,
1077+
method: str,
1078+
url: str,
1079+
*,
1080+
params: typing.Any | None = None,
1081+
headers: typing.Any | None = None,
1082+
cookies: typing.Any | None = None,
1083+
timeout: typing.Any = httpx2.USE_CLIENT_DEFAULT,
1084+
extensions: typing.Any | None = None,
1085+
json: typing.Any | None = None,
1086+
content: typing.Any | None = None,
1087+
data: typing.Any | None = None,
1088+
files: typing.Any | None = None,
1089+
response_model: type[T] | None = None,
1090+
) -> httpx2.Response | T:
1091+
request = self._prepare_request(
1092+
method,
1093+
url,
1094+
params=params,
1095+
headers=headers,
1096+
cookies=cookies,
1097+
timeout=timeout,
1098+
extensions=extensions,
1099+
json=json,
1100+
content=content,
1101+
data=data,
1102+
files=files,
1103+
)
10441104
return self.send(request, response_model=response_model)
10451105

10461106
@typing.overload

0 commit comments

Comments
 (0)