MCPcopy
hub / github.com/encode/httpx / Request

Class Request

httpx/_models.py:382–512  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

380
381
382class Request:
383 def __init__(
384 self,
385 method: str,
386 url: URL | str,
387 *,
388 params: QueryParamTypes | None = None,
389 headers: HeaderTypes | None = None,
390 cookies: CookieTypes | None = None,
391 content: RequestContent | None = None,
392 data: RequestData | None = None,
393 files: RequestFiles | None = None,
394 json: typing.Any | None = None,
395 stream: SyncByteStream | AsyncByteStream | None = None,
396 extensions: RequestExtensions | None = None,
397 ) -> None:
398 self.method = method.upper()
399 self.url = URL(url) if params is None else URL(url, params=params)
400 self.headers = Headers(headers)
401 self.extensions = {} if extensions is None else dict(extensions)
402
403 if cookies:
404 Cookies(cookies).set_cookie_header(self)
405
406 if stream is None:
407 content_type: str | None = self.headers.get("content-type")
408 headers, stream = encode_request(
409 content=content,
410 data=data,
411 files=files,
412 json=json,
413 boundary=get_multipart_boundary_from_content_type(
414 content_type=content_type.encode(self.headers.encoding)
415 if content_type
416 else None
417 ),
418 )
419 self._prepare(headers)
420 self.stream = stream
421 # Load the request body, except for streaming content.
422 if isinstance(stream, ByteStream):
423 self.read()
424 else:
425 # There's an important distinction between `Request(content=...)`,
426 # and `Request(stream=...)`.
427 #
428 # Using `content=...` implies automatically populated `Host` and content
429 # headers, of either `Content-Length: ...` or `Transfer-Encoding: chunked`.
430 #
431 # Using `stream=...` will not automatically include *any*
432 # auto-populated headers.
433 #
434 # As an end-user you don't really need `stream=...`. It's only
435 # useful when:
436 #
437 # * Preserving the request stream when copying requests, eg for redirects.
438 # * Creating request instances on the *server-side* of the transport API.
439 self.stream = stream

Callers 2

build_requestMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected