Skip to content

Commit

Permalink
Issue #1503 Optionally strip IPv6
Browse files Browse the repository at this point in the history
  • Loading branch information
gregw authored and joakime committed Aug 8, 2017
1 parent 8a674ad commit 8e3f950
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@
* Parse an authority string into Host and Port
* <p>Parse a string in the form "host:port", handling IPv4 an IPv6 hosts</p>
*
* <p>The System property "org.eclipse.jetty.util.HostPort.STRIP_IPV6" can be set to a boolean
* value to control of the square brackets are stripped off IPv6 addresses.</p>
*/
public class HostPort
{
private final static boolean STRIP_IPV6 = Boolean.parseBoolean(System.getProperty("org.eclipse.jetty.util.HostPort.STRIP_IPV6","true"));

private final String _host;
private final int _port;

Expand All @@ -45,7 +49,7 @@ else if (authority.charAt(0)=='[')
int close=authority.lastIndexOf(']');
if (close<0)
throw new IllegalArgumentException("Bad IPv6 host");
_host=authority.substring(0,close+1);
_host=STRIP_IPV6?authority.substring(0,close+1):authority.substring(1,close);

if (authority.length()>close+1)
{
Expand Down

0 comments on commit 8e3f950

Please sign in to comment.