Add Host Bindings feature #1015
Open
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.
Pull Request Type
This is a:
Context
This PR adds support for binding specific hostnames to specific IP addresses, bypassing DNS resolution.
This is useful for:
HostheaderDetailed Description
New
HostBindingsutility classA value object that validates and stores hostname-to-IP mappings. Key features:
filter_var(FILTER_VALIDATE_IP)to prevent hostname injection attacks. Accepts both IPv4 and IPv6 addresses (including private/localhost ranges).HostBindings::SKIP_IP_VALIDATION(use with caution).Methods:
has_host($host)- Check if a host has a mappingget_first_ip_for_host($host)- Get the first IP for a host (throwsUnknownHostorMissingIpAddressif not available)get_all_ips_for_host($host)- Get all IPs for a host (throwsUnknownHostif not found)New exceptions
UnknownHost- Thrown when requesting a host that isn't in the bindingsMissingIpAddress- Thrown when a host has no IP addresses configuredNew
HOST_BINDINGScapabilityAdded to the
Capabilityinterface to allow transport capability testing.Transport integration
Curl transport (
Transport\Curl):CURLOPT_CONNECT_TO(cURL 7.49.0+) as the preferred methodCURLOPT_RESOLVE(cURL 7.21.3+) for older cURL versionsHostheaderFsockopen transport (
Transport\Fsockopen):HostheaderUsage
The
host_bindingsoption accepts either an array (with automatic IP validation) or a pre-constructedHostBindingsobject:Includes
HostBindingsclass (constructor validation, all methods)Transport\BaseTestCasecovering both transportsRequests::request()docblock