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

Method _prepare

httpx/_models.py:441–460  ·  httpx/_models.py::Request._prepare
(self, default_headers: dict[str, str])

Source from the content-addressed store, hash-verified

439 self.stream = stream
440
441 def _prepare(self, default_headers: dict[str, str]) -> None:
442 for key, value in default_headers.items():
443 class="cm"># Ignore Transfer-Encoding if the Content-Length has been set explicitly.
444 if key.lower() == class="st">"transfer-encoding" and class="st">"Content-Length" in self.headers:
445 continue
446 self.headers.setdefault(key, value)
447
448 auto_headers: list[tuple[bytes, bytes]] = []
449
450 has_host = class="st">"Host" in self.headers
451 has_content_length = (
452 class="st">"Content-Length" in self.headers or class="st">"Transfer-Encoding" in self.headers
453 )
454
455 if not has_host and self.url.host:
456 auto_headers.append((bclass="st">"Host", self.url.netloc))
457 if not has_content_length and self.method in (class="st">"POST", class="st">"PUT", class="st">"PATCH"):
458 auto_headers.append((bclass="st">"Content-Length", bclass="st">"0"))
459
460 self.headers = Headers(auto_headers + self.headers.raw)
461
462 @property
463 def content(self) -> bytes:

Callers 1

__init__Method · 0.95

Calls 2

HeadersClass · 0.85
itemsMethod · 0.45

Tested by

no test coverage detected