Beispiel #1
0
  /** Add all Cookie found in the headers of a request. */
  public void processCookies(MimeHeaders headers) {
    if (headers == null) {
      return; // nothing to process
    }
    // process each "cookie" header
    int pos = 0;
    while (pos >= 0) {
      // Cookie2: version ? not needed
      pos = headers.findHeader("Cookie", pos);
      // no more cookie headers headers
      if (pos < 0) {
        break;
      }

      MessageBytes cookieValue = headers.getValue(pos);
      if (cookieValue == null || cookieValue.isNull()) {
        pos++;
        continue;
      }

      if (cookieValue.getType() != MessageBytes.T_BYTES) {
        Exception e = new Exception();
        log.warn("Cookies: Parsing cookie as String. Expected bytes.", e);
        cookieValue.toBytes();
      }
      if (log.isDebugEnabled()) {
        log.debug("Cookies: Parsing b[]: " + cookieValue.toString());
      }
      ByteChunk bc = cookieValue.getByteChunk();
      if (CookieSupport.PRESERVE_COOKIE_HEADER) {
        int len = bc.getLength();
        if (len > 0) {
          byte[] buf = new byte[len];
          System.arraycopy(bc.getBytes(), bc.getOffset(), buf, 0, len);
          processCookieHeader(buf, 0, len);
        }
      } else {
        processCookieHeader(bc.getBytes(), bc.getOffset(), bc.getLength());
      }
      pos++; // search from the next position
    }
  }