-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Add IPv6 support in RestTemplate #358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This looks very good overall. A couple of things I noticed while experimenting. If an invalid IPv6 format is used (e.g. omit the closing
|
Good catch. I'll modify my PR and add more tests on edge cases. |
I've changed a couple of things in this PR. I've splitted the host regexp in 2; the match process is getting more complex and I wonder if we should use named groups to make it more readable/manageable. On the first point, I've added a "scheme but no host" check in the I agree, IPv4 and IPv6 are different enough to create a separate I'm not really happy with the condition check to decide on wich |
Prior to this commit, RestTemplate would not would not accept IPv6 raw addresses in URLs because UriComponentsBuilder would not parse/encode the Host part correctly. The UriComponentsBuilder now parses and encode raw IPv6 addresses in the "[1abc:2abc:3abc::5ABC:6abc]" format and also supports the use of IPv6 scope_ids (see JDK8 java.net.Inet6Address), like "[1abc:2abc:3abc::5ABC:6abc%eth0]". Issue: SPR-10539
* bclozel-SPR-10539: Polish Add IPv6 support in RestTemplate
This is now merged.
There are few ways to make it a little nicer but since it is a private matter within HierarchicalUriComponents, the current solution is fine. I did a little polish, just to cover the call to verify(), but the approach is the same. |
PR spring-projectsgh-358 introduced a "scheme but no host" check in the fromHttpUrl() method in UriComponentsBuilder, but a similar check was not added to fromUriString() at that time. This commit introduces a "scheme but no host" check in fromUriString() to align with the functionality in fromHttpUrl(). Note, however that the regular expressions used to match against the hostname or IP address are inexact and still permit invalid host names or IP addresses. True validation of the host portion of the URI is out of scope for this commit. Closes spring-projectsgh-25334
Prior to this commit, RestTemplate would not would
not accept IPv6 raw addresses in URLs because UriComponentsBuilder
would not parse/encode the Host part correctly.
The UriComponentsBuilder now parses and encode raw IPv6 addresses
in the "[1abc:2abc:3abc::5ABC:6abc]" format and also supports the
use of IPv6 scope_ids (see JDK8 java.net.Inet6Address),
like "[1abc:2abc:3abc::5ABC:6abc%eth0]".
Issue: SPR-10539