feat: add PROXY protocol v2 support with version selection#3451
Merged
Conversation
70f4311 to
0da9f0f
Compare
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
0da9f0f to
6faa47f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
--proxy-protocolto accept version values (off,v1,v2,auto) instead of being boolean-only--proxy-protocolalone (orTruein config) maps toautoChanges
InvalidProxyHeaderexception for v2 binary header errorsvalidate_proxy_protocol()validator with backwards compatibilityProxyProtocolsetting withnargs="?"andconst="auto"PP_V2_SIGNATURE,PPCommand,PPFamily,PPProtocol)_parse_proxy_protocol_v1()and_parse_proxy_protocol_v2()methodsmessage.py) and async (asgi/message.py) parserstreq.pyfor v2 binary test dataConfiguration Values
offorfalsev1v2autoortrueCloses #2912