From e215891dd0c76b0c06ee43ec60051e94d7554265 Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Thu, 11 Oct 2007 17:13:53 +0000 Subject: [PATCH] Test if the host name appears to be a fully qualified DNS name, IPv4 address or IPv6 address git-svn-id: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpclient/trunk@583886 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/http/impl/cookie/RFC2965Spec.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/module-client/src/main/java/org/apache/http/impl/cookie/RFC2965Spec.java b/module-client/src/main/java/org/apache/http/impl/cookie/RFC2965Spec.java index 19f179444..67eee1b52 100644 --- a/module-client/src/main/java/org/apache/http/impl/cookie/RFC2965Spec.java +++ b/module-client/src/main/java/org/apache/http/impl/cookie/RFC2965Spec.java @@ -212,11 +212,22 @@ public class RFC2965Spec extends RFC2109Spec { * @return */ private static CookieOrigin adjustEffectiveHost(final CookieOrigin origin) { - String effectiveHost = origin.getHost(); - if (effectiveHost.indexOf('.') < 0) { - effectiveHost += ".local"; + String host = origin.getHost(); + + // Test if the host name appears to be a fully qualified DNS name, + // IPv4 address or IPv6 address + boolean isLocalHost = true; + for (int i = 0; i < host.length(); i++) { + char ch = host.charAt(i); + if (ch == '.' || ch == ':') { + isLocalHost = false; + break; + } + } + if (isLocalHost) { + host += ".local"; return new CookieOrigin( - effectiveHost, + host, origin.getPort(), origin.getPath(), origin.isSecure());