MCPcopy Index your code
hub / github.com/mitmproxy/mitmproxy / parse_transfer_encoding

Function parse_transfer_encoding

mitmproxy/net/http/validate.py:50–63  ·  view source on GitHub ↗

Parse a transfer-encoding header value, or raise a ValueError if it is invalid or unknown.

(value: str | bytes)

Source from the content-addressed store, hash-verified

48
49
50def parse_transfer_encoding(value: str | bytes) -> TransferEncoding:
51 """Parse a transfer-encoding header value, or raise a ValueError if it is invalid or unknown."""
52 # guard against .lower() transforming non-ascii to ascii
53 if not value.isascii():
54 raise ValueError(f"invalid transfer-encoding header: {value!r}")
55 if isinstance(value, str):
56 te = value
57 else:
58 te = value.decode()
59 te = te.lower()
60 te = re.sub(r"[\t ]*,[\t ]*", ",", te)
61 if te not in _HTTP_1_1_TRANSFER_ENCODINGS:
62 raise ValueError(f"unknown transfer-encoding header: {value!r}")
63 return typing.cast(TransferEncoding, te)
64
65
66def validate_headers(message: Message) -> None:

Callers 3

validate_headersFunction · 0.85

Calls 1

decodeMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…