Return Content-Length or 0. Matches only the exact header name.
(header_block: bytes)
| 44 | |
| 45 | |
| 46 | def parse_content_length(header_block: bytes) -> int: |
| 47 | """Return Content-Length or 0. Matches only the exact header name.""" |
| 48 | for raw_line in header_block.split(b"\r\n"): |
| 49 | name, sep, value = raw_line.partition(b":") |
| 50 | if not sep: |
| 51 | continue |
| 52 | if name.strip().lower() == b"content-length": |
| 53 | try: |
| 54 | return int(value.strip()) |
| 55 | except ValueError: |
| 56 | return 0 |
| 57 | return 0 |
| 58 | |
| 59 | |
| 60 | def has_unsupported_transfer_encoding(header_block: bytes) -> bool: |
no outgoing calls