feat: Add IPv6 zone ID detection and parsing support in HTTPAdapter#7065
Draft
feat: Add IPv6 zone ID detection and parsing support in HTTPAdapter#7065
Conversation
|
We really need this issue fixed. Our customers are waiting for it. Others have also requested for a fix. Maintainers have so far completely ignored all requests (no pun intended) and remained silent. |
- Introduced a new helper function `_has_ipv6_zone_id` to detect URLs with IPv6 zone identifiers. - Updated `_urllib3_request_context` to utilize `urllib3`'s `parse_url` for URLs containing zone IDs, ensuring correct parsing and backward compatibility. - Added comprehensive tests for IPv6 zone ID detection and parsing, covering various scenarios in `test_adapters.py`. - Enhanced integration tests to verify connection pool key generation for requests with different zone IDs.
- Included tests for URLs with percent-encoded paths that do not contain zone IDs, ensuring comprehensive coverage of edge cases.
- Updated `_has_ipv6_zone_id` to correctly match both literal '%' and '%25' in URLs. - Improved `_urllib3_request_context` to reconstruct hosts with properly encoded zone IDs, addressing RFC 6874 compliance. - Added extensive test cases in `test_adapters.py` and `test_models.py` to cover various edge cases for zone ID detection and parsing, ensuring robust functionality.
- Removed redundant import of `re` in `_has_ipv6_zone_id` function, as it is now imported at the top of the file. - Cleaned up code for better readability and maintainability.
- Updated the `_has_ipv6_zone_id` function to more accurately distinguish between zone IDs and percent-encoded characters within brackets. - Improved regex patterns to handle both literal '%' and '%25' cases, ensuring compliance with RFC 6874. - Added additional test cases in `test_adapters.py` to cover false positives and edge cases for zone ID detection.
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
This PR possibly solves #6927, #6735 and #7088 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 (+54 -4 lines)src/requests/models.py- Core implementation (+9 lines)tests/test_adapters.py- Test suite (+292 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.