Coerce str/bytes into a strictly byte-wise HTTP header value.
(value: str | bytes, encoding: str | None = None)
| 72 | |
| 73 | |
| 74 | def _normalize_header_value(value: str | bytes, encoding: str | None = None) -> bytes: |
| 75 | class="st">""" |
| 76 | Coerce str/bytes into a strictly byte-wise HTTP header value. |
| 77 | class="st">""" |
| 78 | if isinstance(value, bytes): |
| 79 | return value |
| 80 | if not isinstance(value, str): |
| 81 | raise TypeError(fclass="st">"Header value must be str or bytes, not {type(value)}") |
| 82 | return value.encode(encoding or class="st">"ascii") |
| 83 | |
| 84 | |
| 85 | def _parse_content_type_charset(content_type: str) -> str | None: |