11from collections .abc import Callable , Iterable
2- from typing import Any , Literal , SupportsIndex
2+ from enum import IntEnum
3+ from typing import Any , Final , Literal , SupportsIndex , TypedDict , type_check_only
34from typing_extensions import Self , TypeAlias
45
56_H1CProtocol : TypeAlias = Any # gunicorn_h1c H1CProtocol class
67
78class ParseError (Exception ): ...
9+ class InvalidProxyLine (ParseError ): ...
10+ class InvalidProxyHeader (ParseError ): ...
11+
12+ PP_V2_SIGNATURE : Final [bytes ]
13+
14+ class PPCommand (IntEnum ):
15+ LOCAL = 0x0
16+ PROXY = 0x1
17+
18+ class PPFamily (IntEnum ):
19+ UNSPEC = 0x0
20+ INET = 0x1
21+ INET6 = 0x2
22+ UNIX = 0x3
23+
24+ class PPProtocol (IntEnum ):
25+ UNSPEC = 0x0
26+ STREAM = 0x1
27+ DGRAM = 0x2
28+
829class LimitRequestLine (ParseError ): ...
30+ class InvalidRequestLine (ParseError ): ...
931class LimitRequestHeaders (ParseError ): ...
1032class InvalidRequestMethod (ParseError ): ...
1133class InvalidHTTPVersion (ParseError ): ...
1234class InvalidHeaderName (ParseError ): ...
1335class InvalidHeader (ParseError ): ...
36+ class UnsupportedTransferCoding (ParseError ): ...
37+ class InvalidChunkSize (ParseError ): ...
38+ class InvalidChunkExtension (ParseError ): ...
39+
40+ @type_check_only
41+ class _ProxyProtocolInfo (TypedDict ):
42+ proxy_protocol : Literal ["TCP4" , "TCP6" , "UDP4" , "UDP6" ]
43+ client_addr : str
44+ client_port : int
45+ proxy_addr : str
46+ proxy_port : int
47+
48+ @type_check_only
49+ class _ProxyProtocolInfoUnknown (TypedDict ):
50+ proxy_protocol : Literal ["UNKNOWN" , "LOCAL" , "UNSPEC" ]
51+ client_addr : None
52+ client_port : None
53+ proxy_addr : None
54+ proxy_port : None
1455
1556class PythonProtocol :
1657 __slots__ = (
@@ -42,6 +83,9 @@ class PythonProtocol:
4283 "_permit_unconventional_http_method" ,
4384 "_permit_unconventional_http_version" ,
4485 "_header_count" ,
86+ "_proxy_protocol" ,
87+ "_proxy_protocol_info" ,
88+ "_proxy_protocol_done" ,
4589 )
4690 method : bytes | None
4791 path : bytes | None
@@ -65,9 +109,13 @@ class PythonProtocol:
65109 limit_request_field_size : int = 8190 ,
66110 permit_unconventional_http_method : bool = False ,
67111 permit_unconventional_http_version : bool = False ,
112+ proxy_protocol : Literal ["off" , "v1" , "v2" , "auto" ] = "off" ,
68113 ) -> None : ...
69114 def feed (self , data : Iterable [SupportsIndex ]) -> None : ...
115+ @property
116+ def proxy_protocol_info (self ) -> _ProxyProtocolInfo | _ProxyProtocolInfoUnknown | None : ...
70117 def reset (self ) -> None : ...
118+ def finish (self ) -> None : ...
71119
72120class CallbackRequest :
73121 __slots__ = (
0 commit comments