Parse a content-length header value, or raise a ValueError if it is invalid.
(value: str | bytes)
| 37 | |
| 38 | |
| 39 | def parse_content_length(value: str | bytes) -> int: |
| 40 | """Parse a content-length header value, or raise a ValueError if it is invalid.""" |
| 41 | if isinstance(value, str): |
| 42 | valid = bool(_valid_content_length_str.match(value)) |
| 43 | else: |
| 44 | valid = bool(_valid_content_length.match(value)) |
| 45 | if not valid: |
| 46 | raise ValueError(f"invalid content-length header: {value!r}") |
| 47 | return int(value) |
| 48 | |
| 49 | |
| 50 | def parse_transfer_encoding(value: str | bytes) -> TransferEncoding: |
searching dependent graphs…