Ejemplo n.º 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);
        }
      }
    }
  }
 @Test
 public void createACookieWithNameAndValueAndChangeDomain() {
   Http.Cookie cookie = Http.Cookie.builder("name", "value").withDomain(".example.com").build();
   assertEquals("name", cookie.name());
   assertEquals("value", cookie.value());
   assertEquals("/", cookie.path());
   assertEquals(".example.com", cookie.domain());
   assertEquals(null, cookie.maxAge());
   assertEquals(false, cookie.secure());
   assertEquals(false, cookie.httpOnly());
 }
 @Test
 public void createACookieWithNameAndValueAndKeepDefaults() {
   Http.Cookie cookie = Http.Cookie.builder("name", "value").build();
   assertEquals("name", cookie.name());
   assertEquals("value", cookie.value());
   assertEquals("/", cookie.path());
   assertEquals(null, cookie.domain());
   assertEquals(null, cookie.maxAge());
   assertEquals(false, cookie.secure());
   assertEquals(false, cookie.httpOnly());
 }
 @Test
 public void createACookieWithNameAndValueWithSecureAndHttpOnlyEqualToTrue() {
   Http.Cookie cookie =
       Http.Cookie.builder("name", "value").withSecure(true).withHttpOnly(true).build();
   assertEquals("name", cookie.name());
   assertEquals("value", cookie.value());
   assertEquals("/", cookie.path());
   assertEquals(null, cookie.domain());
   assertEquals(null, cookie.maxAge());
   assertEquals(true, cookie.secure());
   assertEquals(true, cookie.httpOnly());
 }