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