Split HTTP/2 pseudo-headers from the actual headers and parse them.
(
h2_headers: Sequence[tuple[bytes, bytes]],
)
| 658 | |
| 659 | |
| 660 | def 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 | |
| 690 | def parse_h2_response_headers( |
no test coverage detected
searching dependent graphs…