Пример #1
0
  protected static void addToRequest(HttpRequest nettyRequest, Request request) {
    for (String key : nettyRequest.getHeaderNames()) {
      Http.Header hd = new Http.Header();
      hd.name = key.toLowerCase();
      hd.values = new ArrayList<String>();
      for (String next : nettyRequest.getHeaders(key)) {
        hd.values.add(next);
      }
      request.headers.put(hd.name, hd);
    }

    String value = nettyRequest.getHeader(COOKIE);
    if (value != null) {
      Set<Cookie> cookies = new CookieDecoder().decode(value);
      if (cookies != null) {
        for (Cookie cookie : cookies) {
          Http.Cookie playCookie = new Http.Cookie();
          playCookie.name = cookie.getName();
          playCookie.path = cookie.getPath();
          playCookie.domain = cookie.getDomain();
          playCookie.secure = cookie.isSecure();
          playCookie.value = cookie.getValue();
          playCookie.httpOnly = cookie.isHttpOnly();
          request.cookies.put(playCookie.name, playCookie);
        }
      }
    }
  }
Пример #2
0
 @Override
 public void addResponseCookie(final Cookie cookie) {
   javax.servlet.http.Cookie c =
       new javax.servlet.http.Cookie(cookie.getName(), cookie.getValue());
   c.setSecure(cookie.isSecure());
   c.setPath(cookie.getPath());
   c.setMaxAge(cookie.getMaxAge());
   c.setHttpOnly(cookie.isHttpOnly());
   c.setComment(cookie.getComment());
   c.setDomain(cookie.getDomain());
   this.response.addCookie(c);
 }
Пример #3
0
  private String encodeServerSide() {
    StringBuilder sb = new StringBuilder();

    for (Cookie cookie : cookies) {
      add(sb, cookie.getName(), cookie.getValue());

      if (cookie.getMaxAge() >= 0) {
        if (cookie.getVersion() == 0) {
          addUnquoted(
              sb,
              CookieHeaderNames.EXPIRES,
              new HttpHeaderDateFormat()
                  .format(new Date(System.currentTimeMillis() + cookie.getMaxAge() * 1000L)));
        } else {
          add(sb, CookieHeaderNames.MAX_AGE, cookie.getMaxAge());
        }
      }

      if (cookie.getPath() != null) {
        if (cookie.getVersion() > 0) {
          add(sb, CookieHeaderNames.PATH, cookie.getPath());
        } else {
          addUnquoted(sb, CookieHeaderNames.PATH, cookie.getPath());
        }
      }

      if (cookie.getDomain() != null) {
        if (cookie.getVersion() > 0) {
          add(sb, CookieHeaderNames.DOMAIN, cookie.getDomain());
        } else {
          addUnquoted(sb, CookieHeaderNames.DOMAIN, cookie.getDomain());
        }
      }
      if (cookie.isSecure()) {
        sb.append(CookieHeaderNames.SECURE);
        sb.append((char) HttpConstants.SEMICOLON);
      }
      if (cookie.isHttpOnly()) {
        sb.append(CookieHeaderNames.HTTPONLY);
        sb.append((char) HttpConstants.SEMICOLON);
      }
      if (cookie.getVersion() >= 1) {
        if (cookie.getComment() != null) {
          add(sb, CookieHeaderNames.COMMENT, cookie.getComment());
        }

        add(sb, CookieHeaderNames.VERSION, 1);

        if (cookie.getCommentUrl() != null) {
          addQuoted(sb, CookieHeaderNames.COMMENTURL, cookie.getCommentUrl());
        }

        if (!cookie.getPorts().isEmpty()) {
          sb.append(CookieHeaderNames.PORT);
          sb.append((char) HttpConstants.EQUALS);
          sb.append((char) HttpConstants.DOUBLE_QUOTE);
          for (int port : cookie.getPorts()) {
            sb.append(port);
            sb.append((char) HttpConstants.COMMA);
          }
          sb.setCharAt(sb.length() - 1, (char) HttpConstants.DOUBLE_QUOTE);
          sb.append((char) HttpConstants.SEMICOLON);
        }
        if (cookie.isDiscard()) {
          sb.append(CookieHeaderNames.DISCARD);
          sb.append((char) HttpConstants.SEMICOLON);
        }
      }
    }

    if (sb.length() > 0) {
      sb.setLength(sb.length() - 1);
    }

    return sb.toString();
  }