コード例 #1
0
ファイル: RFC2965Spec.java プロジェクト: lasbreyn/grouper
  /**
   * Return <tt>true</tt> if the cookie should be submitted with a request with given attributes,
   * <tt>false</tt> otherwise.
   *
   * @param host the host to which the request is being submitted
   * @param port the port to which the request is being submitted (ignored)
   * @param path the path to which the request is being submitted
   * @param secure <tt>true</tt> if the request is using a secure connection
   * @return true if the cookie matches the criterium
   */
  public boolean match(String host, int port, String path, boolean secure, final Cookie cookie) {

    LOG.trace("enter RFC2965.match(" + "String, int, String, boolean, Cookie");
    if (cookie == null) {
      throw new IllegalArgumentException("Cookie may not be null");
    }
    if (cookie instanceof Cookie2) {
      // check if cookie has expired
      if (cookie.isPersistent() && cookie.isExpired()) {
        return false;
      }
      CookieOrigin origin = new CookieOrigin(getEffectiveHost(host), port, path, secure);
      for (Iterator i = getAttribHandlerIterator(); i.hasNext(); ) {
        CookieAttributeHandler handler = (CookieAttributeHandler) i.next();
        if (!handler.match(cookie, origin)) {
          return false;
        }
      }
      return true;
    } else {
      // old-style cookies are matched according to the old rules
      return this.rfc2109.match(host, port, path, secure, cookie);
    }
  }