public boolean match(final Cookie cookie, final CookieOrigin origin) { if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null"); } if (origin == null) { throw new IllegalArgumentException("Cookie origin may not be null"); } String host = origin.getHost(); String domain = cookie.getDomain(); if (domain == null) { return false; } return host.equals(domain) || (domain.startsWith(".") && host.endsWith(domain)); }
@Override public boolean match(Cookie cookie, CookieOrigin origin) { if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null"); } if (origin == null) { throw new IllegalArgumentException("Cookie origin may not be null"); } String host = origin.getHost(); String domain = cookie.getDomain(); if (domain == null) { return false; } return host.endsWith(domain); }
public int compare(final Cookie c1, final Cookie c2) { int res = c1.getName().compareTo(c2.getName()); if (res == 0) { // do not differentiate empty and null domains String d1 = c1.getDomain(); if (d1 == null) { d1 = ""; } String d2 = c2.getDomain(); if (d2 == null) { d2 = ""; } res = d1.compareToIgnoreCase(d2); } return res; }
public boolean match(final Cookie cookie, final CookieOrigin origin) { if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null"); } if (origin == null) { throw new IllegalArgumentException("Cookie origin may not be null"); } String host = origin.getHost(); String domain = cookie.getDomain(); if (domain == null) { return false; } if (host.equals(domain)) { return true; } if (!domain.startsWith(".")) { domain = '.' + domain; } return host.endsWith(domain) || host.equals(domain.substring(1)); }
public void addCookie(Cookie cookie) { if (isCookieCountMaxedForDomain(cookie.getDomain())) { logger.log( Level.FINEST, "Maximum number of cookies reached for domain " + cookie.getDomain() + ". Will not add new cookie " + cookie.getName() + " with value " + cookie.getValue()); return; } addCookieImpl(cookie); }
/** * Match cookie domain attribute. */ public boolean match(final Cookie cookie, final CookieOrigin origin) { if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null"); } if (origin == null) { throw new IllegalArgumentException("Cookie origin may not be null"); } String host = origin.getHost().toLowerCase(Locale.ENGLISH); String cookieDomain = cookie.getDomain(); // The effective host name MUST domain-match the Domain // attribute of the cookie. if (!domainMatch(host, cookieDomain)) { return false; } // effective host name minus domain must not contain any dots String effectiveHostWithoutDomain = host.substring( 0, host.length() - cookieDomain.length()); return effectiveHostWithoutDomain.indexOf('.') == -1; }
/** * Returns a string that uniquely identifies the cookie, The format The * format of the key is {@code "normalizedDomain;name;path"}. Adapted from * {@link CookieIdentityComparator#compare(Cookie, Cookie)}. */ protected String sortableKey(Cookie cookie) { String normalizedDomain = normalizeHost(cookie.getDomain()); // use ";" as delimiter since it is the delimiter in the cookie header, // so presumably can't appear in any of these values StringBuilder buf = new StringBuilder(normalizedDomain); buf.append(";").append(cookie.getName()); buf.append(";").append(cookie.getPath() != null ? cookie.getPath() : "/"); return buf.toString(); }
if (cookie.getDomain() == null) { throw new MalformedCookieException("Invalid cookie state: " + "domain not specified"); String cookieDomain = cookie.getDomain().toLowerCase(Locale.ENGLISH); cookie.getDomain() + "\" violates RFC 2109: domain must start with a dot"); && (!cookieDomain.equals(".local"))) { throw new MalformedCookieException( "Domain attribute \"" + cookie.getDomain() + "\" violates RFC 2965: the value contains no embedded dots " + "and the value is not .local"); "Domain attribute \"" + cookie.getDomain() + "\" violates RFC 2965: effective host name does not " + "domain-match domain attribute."); if (effectiveHostWithoutDomain.indexOf('.') != -1) { throw new MalformedCookieException("Domain attribute \"" + cookie.getDomain() + "\" violates RFC 2965: " + "effective host minus domain may not contain any dots"); if (!cookie.getDomain().equals(host)) { throw new MalformedCookieException("Illegal domain attribute: \"" + cookie.getDomain() + "\"." + "Domain of origin: \"" + host + "\"");
/** * Don't log the cookie's value; that's potentially sensitive information. */ private String cookieToString(Cookie cookie) { return cookie.getClass().getSimpleName() + "[version=" + cookie.getVersion() + ",name=" + cookie.getName() + ",domain=" + cookie.getDomain() + ",path=" + cookie.getPath() + ",expiry=" + cookie.getExpiryDate() + "]"; } // END android-added
String domain = cookie.getDomain(); if (domain == null) { throw new MalformedCookieException("Cookie domain may not be null");
String domain = cookie.getDomain(); if (domain == null) { throw new MalformedCookieException("Cookie domain may not be null");
@Override public void validate(final Cookie cookie, final CookieOrigin origin) throws MalformedCookieException { super.validate(cookie, origin); // Perform Netscape Cookie draft specific validation String host = origin.getHost(); String domain = cookie.getDomain(); if (host.contains(".")) { int domainParts = new StringTokenizer(domain, ".").countTokens(); if (isSpecialDomain(domain)) { if (domainParts < 2) { throw new MalformedCookieException("Domain attribute \"" + domain + "\" violates the Netscape cookie specification for " + "special domains"); } } else { if (domainParts < 3) { throw new MalformedCookieException("Domain attribute \"" + domain + "\" violates the Netscape cookie specification"); } } } }
line.append(cookie.getDomain()); line.append(tab);
/** * Return a string suitable for sending in a <tt>"Cookie"</tt> header * as defined in RFC 2109 for backward compatibility with cookie version 0 * @param buffer The char array buffer to use for output * @param cookie The {@link Cookie} to be formatted as string * @param version The version to use. */ protected void formatCookieAsVer(final CharArrayBuffer buffer, final Cookie cookie, int version) { formatParamAsVer(buffer, cookie.getName(), cookie.getValue(), version); if (cookie.getPath() != null) { if (cookie instanceof ClientCookie && ((ClientCookie) cookie).containsAttribute(ClientCookie.PATH_ATTR)) { buffer.append("; "); formatParamAsVer(buffer, "$Path", cookie.getPath(), version); } } if (cookie.getDomain() != null) { if (cookie instanceof ClientCookie && ((ClientCookie) cookie).containsAttribute(ClientCookie.DOMAIN_ATTR)) { buffer.append("; "); formatParamAsVer(buffer, "$Domain", cookie.getDomain(), version); } } }
private void printCookie(Cookie cookie) { htmlDocument.add("Name: " + cookie.getName() + "<br/>"); htmlDocument.add("Path: " + cookie.getPath() + "<br/>"); htmlDocument.add("Domain: " + cookie.getDomain() + "<br/>"); htmlDocument.add("Value: " + cookie.getValue() + "<br/>"); }
Key(Cookie c) { Domain = c.getDomain(); Path = c.getPath(); Name = c.getName(); }
@Override public boolean match(final Cookie cookie, final CookieOrigin origin) { Args.notNull(cookie, "Cookie"); Args.notNull(origin, "Cookie origin"); final String host = origin.getHost(); final String domain = cookie.getDomain(); if (domain == null) { return false; } return host.endsWith(domain); }
public void validate(final Cookie cookie, final CookieOrigin origin) throws MalformedCookieException { if (origin != null && origin.getHost() != null && cookie != null) { String hostPort = origin.getHost() + ":" + origin.getPort(); String domain = cookie.getDomain(); if (hostPort.equals(domain)) { return; } } super.validate(cookie, origin); }
@Override public boolean match(final Cookie cookie, final CookieOrigin origin) { if (origin != null && origin.getHost() != null && cookie != null) { String hostPort = origin.getHost() + ":" + origin.getPort(); String domain = cookie.getDomain(); if (hostPort.equals(domain)) { return true; } } return super.match(cookie, origin); } }
@Test public void testApacheCookielInputNullDomain() { org.apache.http.cookie.Cookie resultCookie = CookieUtils.asApacheCookie(cookie); assertTrue(resultCookie.getName().equals("key1")); assertTrue(resultCookie.getValue().equals("value1")); assertTrue(resultCookie.getDomain() == null); }