feat: Add IPv6 zone ID detection and parsing support in HTTPAdapter #7065
+216
−4
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
This PR possibly solves #6927 and #6735 by adding support for IPv6 zone identifiers (also known as scope IDs) in URLs and enabling proper handling of link-local IPv6 addresses with zone identifiers like
http://[fe80::1%eth0]/.Background
IPv6 zone identifiers are used to disambiguate link-local addresses (addresses in the
fe80::/10range) that may exist on multiple network interfaces. The zone ID is appended to the address with a%delimiter, such asfe80::1%eth0. Previously, requests did not properly handle these URLs, which could lead to connection issues or parsing errors.Changes Made
_has_ipv6_zone_id()to detect URLs containing IPv6 zone identifiers_urllib3_request_context()to useurllib3'sparse_urlfor URLs with zone IDs, ensuring correct parsing while maintaining backward compatibility for standard URLstest_adapters.pycovering:Files Changed
src/requests/adapters.py- Core implementation (+52 lines)tests/test_adapters.py- Test suite (+164 lines)Testing
All new functionality is covered by comprehensive tests that verify:
Backward Compatibility
This change is fully backward compatible. Standard URLs without IPv6 zone identifiers continue to use the existing parsing logic, while only URLs with detected zone IDs utilize the enhanced
urllib3parsing pathway.