MCPcopy Create free account
hub / github.com/apify/crawlee-python / _build_request

Method _build_request

src/crawlee/http_clients/_httpx.py:258–281  ·  view source on GitHub ↗

Build an `httpx.Request` using the provided parameters.

(
        self,
        client: httpx.AsyncClient,
        url: str,
        method: HttpMethod,
        headers: HttpHeaders | dict[str, str] | None,
        payload: HttpPayload | None,
        session: Session | None = None,
        timeout: httpx.Timeout | None = None,
    )

Source from the content-addressed store, hash-verified

256 await response.aclose()
257
258 def _build_request(
259 self,
260 client: httpx.AsyncClient,
261 url: str,
262 method: HttpMethod,
263 headers: HttpHeaders | dict[str, str] | None,
264 payload: HttpPayload | None,
265 session: Session | None = None,
266 timeout: httpx.Timeout | None = None,
267 ) -> httpx.Request:
268 """Build an `httpx.Request` using the provided parameters."""
269 if isinstance(headers, dict) or headers is None:
270 headers = HttpHeaders(headers or {})
271
272 headers = self._combine_headers(headers)
273
274 return client.build_request(
275 url=url,
276 method=method,
277 headers=dict(headers) if headers else None,
278 content=payload,
279 extensions={'crawlee_session': session if self._persist_cookies_per_session else None},
280 timeout=timeout or httpx.USE_CLIENT_DEFAULT,
281 )
282
283 def _get_client(self, proxy_url: str | None) -> httpx.AsyncClient:
284 """Retrieve or create an HTTP client for the given proxy URL.

Callers 2

send_requestMethod · 0.95
streamMethod · 0.95

Calls 2

_combine_headersMethod · 0.95
HttpHeadersClass · 0.90

Tested by

no test coverage detected