MCPcopy Create free account
hub / github.com/mitmproxy/mitmproxy / parse_content_length

Function parse_content_length

mitmproxy/net/http/validate.py:39–47  ·  view source on GitHub ↗

Parse a content-length header value, or raise a ValueError if it is invalid.

(value: str | bytes)

Source from the content-addressed store, hash-verified

37
38
39def 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
50def parse_transfer_encoding(value: str | bytes) -> TransferEncoding:

Callers 3

validate_headersFunction · 0.85

Calls 1

matchMethod · 0.45

Tested by 2

Used in the wild real call sites across dependent graphs

searching dependent graphs…