Skip to content

feat: Add IPv6 zone ID detection and parsing support in HTTPAdapter#7065

Draft
tboy1337 wants to merge 5 commits intopsf:mainfrom
tboy1337:edit-14
Draft

feat: Add IPv6 zone ID detection and parsing support in HTTPAdapter#7065
tboy1337 wants to merge 5 commits intopsf:mainfrom
tboy1337:edit-14

Conversation

@tboy1337
Copy link
Copy Markdown

@tboy1337 tboy1337 commented Oct 23, 2025

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::/10 range) that may exist on multiple network interfaces. The zone ID is appended to the address with a % delimiter, such as fe80::1%eth0. Previously, requests did not properly handle these URLs, which could lead to connection issues or parsing errors.

Changes Made

  • New helper function: Added _has_ipv6_zone_id() to detect URLs containing IPv6 zone identifiers
  • Enhanced URL parsing: Updated _urllib3_request_context() to use urllib3's parse_url for URLs with zone IDs, ensuring correct parsing while maintaining backward compatibility for standard URLs
  • Comprehensive test coverage: Added extensive unit and integration tests in test_adapters.py covering:
    • Detection of various IPv6 zone ID formats
    • Correct parsing of URLs with zone identifiers
    • Connection pool key generation for different zone IDs
    • Edge cases and error scenarios

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:

  • IPv6 zone ID detection logic
  • Correct URL parsing behavior
  • Connection pool isolation based on zone IDs
  • Backward compatibility with existing URL handling

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 urllib3 parsing pathway.

@tboy1337 tboy1337 changed the title Add IPv6 zone ID detection and parsing support in HTTPAdapter feat: Add IPv6 zone ID detection and parsing support in HTTPAdapter Oct 24, 2025
@ani-sinha
Copy link
Copy Markdown

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.

tboy1337 added 3 commits April 1, 2026 13:44
- 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.
tboy1337 added 2 commits April 1, 2026 13:53
- 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.
@tboy1337 tboy1337 marked this pull request as draft April 1, 2026 08:05
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.

2 participants