users@servlet-spec.java.net

[servlet-spec users] Re: [97-getServerNameAndIPv6] Discussion

From: Greg Wilkins <gregw_at_intalio.com>
Date: Wed, 30 Jul 2014 13:20:40 +1000

On 25 July 2014 11:13, Edward Burns <edward.burns_at_oracle.com> wrote:

> >>>>> On Mon, 30 Jun 2014 16:43:16 +0200, Greg Wilkins <gregw_at_intalio.com>
> said:
>
> GW> I think we need to clarify the handling of raw IPv6 addresses when
> they are
> GW> sent as part of the URI authority and/or Host header.
>
> GW> Currently the javadoc for getServerName says:
>
> Agreed, I've filed: https://java.net/jira/browse/SERVLET_SPEC-97.
>
>
Opps I had already opened https://java.net/jira/browse/SERVLET_SPEC-93


> Is it possible to unambiguously determine if the hostname is an IPv6
> hostname or an IPv4 hostname?
>

 I think so, as the BNF in RFC3986 says:

authority = [ userinfo "@" ] host [ ":" port ]
host = IP-literal / IPv4address / reg-name
IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
IP-literal = "[" ( IPv6address / IPvFuture ) "]"
IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
reg-name = *( unreserved / pct-encoded / sub-delims )
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
pct-encoded = "%" HEXDIG HEXDIG
sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="


So since [ is not in reg-name (unreservced, pct-encoded or sub-delims) and
it not in IPv4address, then we can always tell an IPv6 literal address from
a hostname.

cheers



-- 
Greg Wilkins <gregw_at_intalio.com>
http://eclipse.org/jetty HTTP, SPDY, Websocket server and client that scales
http://www.webtide.com  advice and support for jetty and cometd.