Skip to content

Conversation

@tboy1337
Copy link

@tboy1337 tboy1337 commented Oct 23, 2025

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::/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 (+52 lines)
  • tests/test_adapters.py - Test suite (+164 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.

- 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.
@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
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