| 15 | |
| 16 | |
| 17 | def get_header(scope: dict[str, Any], name: str) -> str | None: |
| 18 | headers_object = scope.get("headers") |
| 19 | if headers_object is None: |
| 20 | return None |
| 21 | |
| 22 | headers = cast("list[tuple[object, object]]", headers_object) |
| 23 | target = name.lower().encode("latin1") |
| 24 | try: |
| 25 | for key, value in headers: |
| 26 | is_match = ( |
| 27 | isinstance(key, (bytes, bytearray)) |
| 28 | and bytes(key).lower() == target |
| 29 | ) |
| 30 | if is_match: |
| 31 | if isinstance(value, (bytes, bytearray)): |
| 32 | return bytes(value).decode("latin1") |
| 33 | return str(value) |
| 34 | except Exception: |
| 35 | return None |
| 36 | return None |
| 37 | |
| 38 | |
| 39 | async def drain_body( |