mirror of
https://github.com/frappe/gunicorn.git
synced 2026-07-03 03:01:31 +08:00
Extend --proxy-protocol to accept version values (off, v1, v2, auto) instead of being boolean-only. This allows explicit control over which PROXY protocol versions are accepted. Changes: - Add InvalidProxyHeader exception for v2 binary header errors - Add validate_proxy_protocol() validator with backwards compatibility - Update ProxyProtocol setting with nargs="?" and const="auto" - Add PROXY v2 constants (PP_V2_SIGNATURE, PPCommand, PPFamily, PPProtocol) - Add _parse_proxy_protocol_v1() and _parse_proxy_protocol_v2() methods - Update both sync (message.py) and async (asgi/message.py) parsers - Add hex escape handling in treq.py for v2 binary test data - Add test cases for v2 TCPv4 and TCPv6 Backwards compatible: --proxy-protocol alone (or True) maps to "auto". Closes #2912
16 lines
283 B
Python
16 lines
283 B
Python
from gunicorn.config import Config
|
|
|
|
cfg = Config()
|
|
cfg.set("proxy_protocol", True)
|
|
|
|
request = {
|
|
"method": "GET",
|
|
"uri": uri("/no/proxy/header"),
|
|
"version": (1, 1),
|
|
"headers": [
|
|
("HOST", "example.com"),
|
|
("CONTENT-LENGTH", "0")
|
|
],
|
|
"body": b""
|
|
}
|