本文整理了Java中org.apache.http.cookie.Cookie.getDomain()
方法的一些代码示例,展示了Cookie.getDomain()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cookie.getDomain()
方法的具体详情如下:
包路径:org.apache.http.cookie.Cookie
类名称:Cookie
方法名:getDomain
[英]Returns domain attribute of the cookie.
[中]返回cookie的域属性。
代码示例来源:origin: robovm/robovm
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));
}
代码示例来源:origin: robovm/robovm
@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);
}
代码示例来源:origin: robovm/robovm
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;
}
代码示例来源:origin: robovm/robovm
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));
}
代码示例来源:origin: internetarchive/heritrix3
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);
}
代码示例来源:origin: robovm/robovm
/**
* 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;
}
代码示例来源:origin: internetarchive/heritrix3
/**
* 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();
}
代码示例来源:origin: robovm/robovm
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 + "\"");
代码示例来源:origin: robovm/robovm
/**
* 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
代码示例来源:origin: robovm/robovm
String domain = cookie.getDomain();
if (domain == null) {
throw new MalformedCookieException("Cookie domain may not be null");
代码示例来源:origin: robovm/robovm
String domain = cookie.getDomain();
if (domain == null) {
throw new MalformedCookieException("Cookie domain may not be null");
代码示例来源:origin: robovm/robovm
@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");
}
}
}
}
代码示例来源:origin: internetarchive/heritrix3
line.append(cookie.getDomain());
line.append(tab);
代码示例来源:origin: robovm/robovm
/**
* 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);
}
}
}
代码示例来源:origin: org.doctester/doctester-core
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/>");
}
代码示例来源:origin: adolfAn/FBReader_AS
Key(Cookie c) {
Domain = c.getDomain();
Path = c.getPath();
Name = c.getName();
}
代码示例来源:origin: Nextdoor/bender
@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);
}
代码示例来源:origin: org.apache.solr/solr-solrj
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);
}
代码示例来源:origin: org.apache.solr/solr-solrj
@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);
}
}
代码示例来源:origin: ViDA-NYU/ache
@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);
}
内容来源于网络,如有侵权,请联系作者删除!