Skip to content

feat: add PROXY protocol v2 support with version selection#3451

Merged
benoitc merged 1 commit into
masterfrom
feat/proxy-protocol-v2
Jan 23, 2026
Merged

feat: add PROXY protocol v2 support with version selection#3451
benoitc merged 1 commit into
masterfrom
feat/proxy-protocol-v2

Conversation

@benoitc
Copy link
Copy Markdown
Owner

@benoitc benoitc commented Jan 23, 2026

Summary

  • Extend --proxy-protocol to accept version values (off, v1, v2, auto) instead of being boolean-only
  • Add PROXY protocol v2 (binary format) parsing support
  • Backwards compatible: --proxy-protocol alone (or True in config) maps to auto

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

Configuration Values

Value Description
off or false Disabled (default)
v1 PROXY v1 only (text format)
v2 PROXY v2 only (binary format)
auto or true Auto-detect v1/v2

Closes #2912

@benoitc benoitc force-pushed the feat/proxy-protocol-v2 branch 3 times, most recently from 70f4311 to 0da9f0f Compare January 23, 2026 17:34
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
@benoitc benoitc force-pushed the feat/proxy-protocol-v2 branch from 0da9f0f to 6faa47f Compare January 23, 2026 17:37
@benoitc benoitc merged commit f3190f8 into master Jan 23, 2026
27 of 28 checks passed
@benoitc benoitc deleted the feat/proxy-protocol-v2 branch January 23, 2026 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant