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
This commit is contained in:
Oleg Kalnichevski 2007-10-11 17:13:53 +00:00
parent 19e029924f
commit e215891dd0
1 changed files with 15 additions and 4 deletions

View File

@ -212,11 +212,22 @@ public class RFC2965Spec extends RFC2109Spec {
* @return * @return
*/ */
private static CookieOrigin adjustEffectiveHost(final CookieOrigin origin) { private static CookieOrigin adjustEffectiveHost(final CookieOrigin origin) {
String effectiveHost = origin.getHost(); String host = origin.getHost();
if (effectiveHost.indexOf('.') < 0) {
effectiveHost += ".local"; // 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( return new CookieOrigin(
effectiveHost, host,
origin.getPort(), origin.getPort(),
origin.getPath(), origin.getPath(),
origin.isSecure()); origin.isSecure());