| 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: |