當前位置: 首頁>>代碼示例>>Java>>正文


Java Cookie.isDomainAttributeSpecified方法代碼示例

本文整理匯總了Java中org.apache.commons.httpclient.Cookie.isDomainAttributeSpecified方法的典型用法代碼示例。如果您正苦於以下問題:Java Cookie.isDomainAttributeSpecified方法的具體用法?Java Cookie.isDomainAttributeSpecified怎麽用?Java Cookie.isDomainAttributeSpecified使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.httpclient.Cookie的用法示例。


在下文中一共展示了Cookie.isDomainAttributeSpecified方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: formatCookieAsVer

import org.apache.commons.httpclient.Cookie; //導入方法依賴的package包/類
/**
 * 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 string buffer to use for output
 * @param cookie The {@link Cookie} to be formatted as string
 * @param version The version to use.
 */
private void formatCookieAsVer(final StringBuffer buffer, final Cookie cookie, int version) {
    String value = cookie.getValue();
    if (value == null) {
        value = "";
    }
    formatParam(buffer, new NameValuePair(cookie.getName(), value), version);
    if ((cookie.getPath() != null) && cookie.isPathAttributeSpecified()) {
      buffer.append("; ");
      formatParam(buffer, new NameValuePair("$Path", cookie.getPath()), version);
    }
    if ((cookie.getDomain() != null) 
        && cookie.isDomainAttributeSpecified()) {
        buffer.append("; ");
        formatParam(buffer, new NameValuePair("$Domain", cookie.getDomain()), version);
    }
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:24,代碼來源:RFC2109Spec.java

示例2: validate

import org.apache.commons.httpclient.Cookie; //導入方法依賴的package包/類
/**
 * Validate cookie domain attribute.
 */
public void validate(final Cookie cookie, final CookieOrigin origin)
        throws MalformedCookieException {
    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();
    if (cookie.getDomain() == null) {
        throw new MalformedCookieException("Invalid cookie state: " +
                                           "domain not specified");
    }
    String cookieDomain = cookie.getDomain().toLowerCase();

    if (cookie.isDomainAttributeSpecified()) {
        // Domain attribute must start with a dot
        if (!cookieDomain.startsWith(".")) {
            throw new MalformedCookieException("Domain attribute \"" +
                cookie.getDomain() + "\" violates RFC 2109: domain must start with a dot");
        }

        // Domain attribute must contain atleast one embedded dot,
        // or the value must be equal to .local.
        int dotIndex = cookieDomain.indexOf('.', 1);
        if (((dotIndex < 0) || (dotIndex == cookieDomain.length() - 1))
            && (!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");
        }

        // The effective host name must domain-match domain attribute.
        if (!domainMatch(host, cookieDomain)) {
            throw new MalformedCookieException(
                    "Domain attribute \"" + cookie.getDomain()
                    + "\" violates RFC 2965: effective host name does not "
                    + "domain-match domain attribute.");
        }

        // effective host name minus domain must not contain any dots
        String effectiveHostWithoutDomain = host.substring(
                0, host.length() - cookieDomain.length());
        if (effectiveHostWithoutDomain.indexOf('.') != -1) {
            throw new MalformedCookieException("Domain attribute \""
                                               + cookie.getDomain() + "\" violates RFC 2965: "
                                               + "effective host minus domain may not contain any dots");
        }
    } else {
        // Domain was not specified in header. In this case, domain must
        // string match request host (case-insensitive).
        if (!cookie.getDomain().equals(host)) {
            throw new MalformedCookieException("Illegal domain attribute: \""
                                               + cookie.getDomain() + "\"."
                                               + "Domain of origin: \""
                                               + host + "\"");
        }
    }
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:64,代碼來源:RFC2965Spec.java

示例3: validate

import org.apache.commons.httpclient.Cookie; //導入方法依賴的package包/類
/**
  * Performs RFC 2109 compliant {@link Cookie} validation
  *
  * @param host the host from which the {@link Cookie} was received
  * @param port the port from which the {@link Cookie} was received
  * @param path the path from which the {@link Cookie} was received
  * @param secure <tt>true</tt> when the {@link Cookie} was received using a
  * secure connection
  * @param cookie The cookie to validate
  * @throws MalformedCookieException if an exception occurs during
  * validation
  */
public void validate(String host, int port, String path, 
    boolean secure, final Cookie cookie) throws MalformedCookieException {
        
    LOG.trace("enter RFC2109Spec.validate(String, int, String, "
        + "boolean, Cookie)");
        
    // Perform generic validation
    super.validate(host, port, path, secure, cookie);
    // Perform RFC 2109 specific validation
    
    if (cookie.getName().indexOf(' ') != -1) {
        throw new MalformedCookieException("Cookie name may not contain blanks");
    }
    if (cookie.getName().startsWith("$")) {
        throw new MalformedCookieException("Cookie name may not start with $");
    }
    
    if (cookie.isDomainAttributeSpecified() 
        && (!cookie.getDomain().equals(host))) {
            
        // domain must start with dot
        if (!cookie.getDomain().startsWith(".")) {
            throw new MalformedCookieException("Domain attribute \"" 
                + cookie.getDomain() 
                + "\" violates RFC 2109: domain must start with a dot");
        }
        // domain must have at least one embedded dot
        int dotIndex = cookie.getDomain().indexOf('.', 1);
        if (dotIndex < 0 || dotIndex == cookie.getDomain().length() - 1) {
            throw new MalformedCookieException("Domain attribute \"" 
                + cookie.getDomain() 
                + "\" violates RFC 2109: domain must contain an embedded dot");
        }
        host = host.toLowerCase();
        if (!host.endsWith(cookie.getDomain())) {
            throw new MalformedCookieException(
                "Illegal domain attribute \"" + cookie.getDomain() 
                + "\". Domain of origin: \"" + host + "\"");
        }
        // host minus domain may not contain any dots
        String hostWithoutDomain = host.substring(0, host.length() 
            - cookie.getDomain().length());
        if (hostWithoutDomain.indexOf('.') != -1) {
            throw new MalformedCookieException("Domain attribute \"" 
                + cookie.getDomain() 
                + "\" violates RFC 2109: host minus domain may not contain any dots");
        }
    }
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:62,代碼來源:RFC2109Spec.java


注:本文中的org.apache.commons.httpclient.Cookie.isDomainAttributeSpecified方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。