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

Method _prepare

httpx/_models.py:441–460  ·  view source on GitHub ↗
(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 # Ignore Transfer-Encoding if the Content-Length has been set explicitly.
444 if key.lower() == "transfer-encoding" and "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 = "Host" in self.headers
451 has_content_length = (
452 "Content-Length" in self.headers or "Transfer-Encoding" in self.headers
453 )
454
455 if not has_host and self.url.host:
456 auto_headers.append((b"Host", self.url.netloc))
457 if not has_content_length and self.method in ("POST", "PUT", "PATCH"):
458 auto_headers.append((b"Content-Length", b"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