Repository navigation
context: handle IPv6 addresses in getHost() and getPort() - #4030
Merged
Merged
Conversation
getHost() and getPort() split the Host header at its first colon, so an IPv6 literal such as [::1]:8080 or [2001:db8::1] gave the host "[" or "2001" and made getPort(), and with it getRequestURL(), throw a NumberFormatException (400). The port of an IPv6 address now comes after the closing bracket, and getHost() returns the address in brackets, as in the Host header.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4030 +/- ##
============================================
+ Coverage 94.17% 94.19% +0.01%
- Complexity 6667 6674 +7
============================================
Files 432 432
Lines 20914 20923 +9
Branches 2102 2106 +4
============================================
+ Hits 19696 19708 +12
+ Misses 764 760 -4
- Partials 454 455 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
jknack
added a commit
that referenced
this pull request
Oct 26, 2026
fixes #4030 - handle `::1` or `::` IPv6 - add more tests
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.
DefaultContext.getHost()andgetPort()split the host-and-port value at its first:. With an IPv6 address in theHostheader (a browser sendsHost: [::1]:8080forhttp://[::1]:8080/), that gives:HostgetHost()getPort()getRequestURL()[::1]:8080[NumberFormatExceptionNumberFormatException[2001:db8::1]2001NumberFormatExceptionNumberFormatException[::1]::180http://::1/pathso a handler that calls
getPort()orgetRequestURL()responds with 400 on every server.The port of an IPv6 address is now taken after the closing bracket, and an address without brackets (
getHostAndPort()returns[::1]as::1) has no port.getHost()returns the address in brackets, as it appears in theHostheader and asProxyPeerAddressalready sets it forX-Forwarded-Host. With that,getRequestURL()buildshttp://[::1]:8080/path.getHostAndPort()and the results for host names and IPv4 addresses don't change.Tests:
DefaultContextTesthas new cases for[2001:db8::1]:8080, for[2001:db8::1]with the default port, forgetRequestURL()with[::1]:8080, and an extragetHost()assertion inhostAndPortIPv6. All four fail without the change.mvn testpasses in thejoobymodule (1310 tests), and google-java-format reports nothing on the changed lines.