Initialize from an HTTP/2 stream. Args: stream: HTTP2Stream instance with received headers/body cfg: Gunicorn configuration object peer_addr: Client address tuple (host, port)
(self, stream, cfg, peer_addr)
| 89 | """ |
| 90 | |
| 91 | def __init__(self, stream, cfg, peer_addr): |
| 92 | """Initialize from an HTTP/2 stream. |
| 93 | |
| 94 | Args: |
| 95 | stream: HTTP2Stream instance with received headers/body |
| 96 | cfg: Gunicorn configuration object |
| 97 | peer_addr: Client address tuple (host, port) |
| 98 | """ |
| 99 | self.stream = stream |
| 100 | self.cfg = cfg |
| 101 | self.peer_addr = peer_addr |
| 102 | self.remote_addr = peer_addr |
| 103 | |
| 104 | # HTTP/2 version tuple |
| 105 | self.version = (2, 0) |
| 106 | |
| 107 | # Parse pseudo-headers |
| 108 | pseudo = stream.get_pseudo_headers() |
| 109 | self.method = pseudo.get(':method', 'GET') |
| 110 | self.scheme = pseudo.get(':scheme', 'https') |
| 111 | authority = pseudo.get(':authority', '') |
| 112 | path = pseudo.get(':path', '/') |
| 113 | |
| 114 | # Parse the path into components |
| 115 | self.uri = path |
| 116 | try: |
| 117 | parts = split_request_uri(path) |
| 118 | self.path = parts.path or "" |
| 119 | self.query = parts.query or "" |
| 120 | self.fragment = parts.fragment or "" |
| 121 | except ValueError: |
| 122 | self.path = path |
| 123 | self.query = "" |
| 124 | self.fragment = "" |
| 125 | |
| 126 | # Store authority for Host header equivalent |
| 127 | self._authority = authority |
| 128 | |
| 129 | # Convert HTTP/2 headers to HTTP/1.1 style |
| 130 | # HTTP/2 headers are lowercase, convert to uppercase for WSGI |
| 131 | self.headers = [] |
| 132 | for name, value in stream.get_regular_headers(): |
| 133 | # Convert to uppercase for WSGI compatibility |
| 134 | self.headers.append((name.upper(), value)) |
| 135 | |
| 136 | # Set Host header from :authority (RFC 9113 section 8.3.1) |
| 137 | # :authority MUST take precedence over Host header |
| 138 | if authority: |
| 139 | self.headers = [(n, v) for n, v in self.headers if n != 'HOST'] |
| 140 | self.headers.append(('HOST', authority)) |
| 141 | |
| 142 | # Trailers (if any) |
| 143 | self.trailers = [] |
| 144 | if stream.trailers: |
| 145 | self.trailers = [ |
| 146 | (name.upper(), value) |
| 147 | for name, value in stream.trailers |
| 148 | ] |
nothing calls this directly
no test coverage detected