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

Function parse_h2_request_headers

mitmproxy/proxy/layers/http/_http2.py:660–687  ·  view source on GitHub ↗

Split HTTP/2 pseudo-headers from the actual headers and parse them.

(
    h2_headers: Sequence[tuple[bytes, bytes]],
)

Source from the content-addressed store, hash-verified

658
659
660def parse_h2_request_headers(
661 h2_headers: Sequence[tuple[bytes, bytes]],
662) -> tuple[str, int, bytes, bytes, bytes, bytes, http.Headers]:
663 """Split HTTP/2 pseudo-headers from the actual headers and parse them."""
664 pseudo_headers, headers = split_pseudo_headers(h2_headers)
665
666 try:
667 method: bytes = pseudo_headers.pop(b":method")
668 scheme: bytes = pseudo_headers.pop(
669 b":scheme"
670 ) # this raises for HTTP/2 CONNECT requests
671 path: bytes = pseudo_headers.pop(b":path")
672 authority: bytes = pseudo_headers.pop(b":authority", b"")
673 except KeyError as e:
674 raise ValueError(f"Required pseudo header is missing: {e}")
675
676 if pseudo_headers:
677 raise ValueError(f"Unknown pseudo headers: {pseudo_headers}")
678
679 if authority:
680 host, port = url.parse_authority(authority, check=True)
681 if port is None:
682 port = 80 if scheme == b"http" else 443
683 else:
684 host = ""
685 port = 0
686
687 return host, port, method, scheme, authority, path, headers
688
689
690def parse_h2_response_headers(

Callers 2

handle_h2_eventMethod · 0.85
parse_headersMethod · 0.85

Calls 2

split_pseudo_headersFunction · 0.85
popMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…