Fix handling of IPv6 literal hosts in Net::HTTPGenericRequest
#237
+42
−7
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.
Background
When an IPv6 literal URI is passed as
uri_or_pathtoNet::HTTPGenericRequest, an issue in IPv6 handling causes the HTTP request headerHostto become incorrect.For example, it becomes
::1:8000instead of[::1]:8000.This incorrect
Hostheader leads to the following problems:http://[::1]result in an error with uri v1.0.4 - 1.1.0HostheaderDetails
This Pull Request fixes the handling of IPv6 literal hosts in
Net::HTTPGenericRequestwhen a URI with an IPv6 literal is passed.(This Pull Request revises and improves upon Pull Request #156.)
With this change, the
Hostheader in HTTP requests generated from IPv6 literal URIs will now have the correct format.Since this fix only resolves cases that previously caused HTTP 400 Bad Request errors, I think it does not introduce any compatibility issues.
Host: 2001:db8::1:8000Host: [2001:db8::1]:8000The behavior for non-IPv6 literal URIs remains unchanged.
Expected behavior
Hostheader (req['Host']) returns an correct valueNet::HTTPGenericRequest#update_uriwithhttp://[::1]Actual behavior
Hostheader (req['Host']) returns an incorrect valueNet::HTTPGenericRequest#update_uriraisesURI::InvalidComponentErrorwithhttp://[::1]when using uri v1.0.4 - 1.1.0System configuration
Additional Information
The CI errors intest (2.7 / windows-latest)andtest (2.6 / windows-latest)are unrelated to this fix and will be resolved once #236 is merged.(It resolved by power_assert v3.0.1.)