Пример #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);
        }
      }
    }
  }
  /**
   * Does something with a session id. It will use the session id provided by the client inside the
   * http server request. If it cannot find it, it will create a new session.
   *
   * @param req The http server request.
   * @param handler The handler to call with the created or found session id.
   */
  public void withSessionId(final HttpServerRequest req, final Handler<String> handler) {
    String value = req.headers().get("Cookie");
    if (value != null) {
      Set<Cookie> cookies = new CookieDecoder().decode(value);
      for (final Cookie cookie : cookies) {
        if (cookieField.equals(cookie.getName())) {
          handler.handle(cookie.getValue());
          return;
        }
      }
    }

    startSession(req, handler);
  }
Пример #3
0
  /**
   * Get all client cookie, return map
   *
   * @return cookie key-value map
   */
  @Override
  public Map<String, String> getCookieMap() {
    if (cookieMap == null) {
      Set<Cookie> cookies;
      String value = headers().get(HttpHeaders.Names.COOKIE);
      if (value == null) {
        cookies = Collections.emptySet();
      } else {
        cookies = getCookieDecoder().decode(value);
      }

      if (cookies != null && cookies.size() > 0) {
        cookieMap = new HashMap<String, String>(cookies.size());
        for (Cookie cookie : cookies) {
          cookieMap.put(cookie.getName(), cookie.getValue());
        }
      } else {
        cookieMap = Collections.emptyMap();
      }
    }

    return cookieMap;
  }