Package io.netty.handler.codec.http

Examples of io.netty.handler.codec.http.DefaultCookie


import io.netty.handler.codec.http.DefaultCookie;
import io.netty.handler.codec.http.ServerCookieEncoder;

public class Cookies {
    public String encodeCookie(String key, String value) {
        Cookie cookie = new DefaultCookie(key, value);
        cookie.setPath("/");
        return ServerCookieEncoder.encode(cookie);
    }
View Full Code Here


    cookies.add(cookie);
  }

  @Override
  public void setCookie(final String name, final String value) {
    cookies.add(new DefaultCookie(name, value));
  }
View Full Code Here

    cookies.add(cookie);
  }

  @Override
  public void setCookie(final String name, final String value) {
    cookies.add(new DefaultCookie(name, value));
  }
View Full Code Here

    cookies.add(cookie);
  }

  @Override
  public void setCookie(final String name, final String value) {
    cookies.add(new DefaultCookie(name, value));
  }
View Full Code Here

        // headers.set("Connection","keep-alive");
        // headers.set("Keep-Alive","300");

        headers.set(
                HttpHeaders.Names.COOKIE, ClientCookieEncoder.encode(
                        new DefaultCookie("my-cookie", "foo"),
                        new DefaultCookie("another-cookie", "bar"))
        );

        // send request
        List<Entry<String, String>> entries = headers.entries();
        channel.writeAndFlush(request);
View Full Code Here

    cookies.add(cookie);
  }

  @Override
  public void setCookie(final String name, final String value) {
    cookies.add(new DefaultCookie(name, value));
  }
View Full Code Here

    sessionManager.notifySessionInitiated(id);
    return id;
  }

  private void setCookie(String value, int expiryMins) {
    DefaultCookie cookie = new DefaultCookie(COOKIE_NAME, value);

    String cookieDomain = sessionManager.getCookieDomain();
    if (cookieDomain != null) {
      cookie.setDomain(cookieDomain);
    }

    String cookiePath = sessionManager.getCookiePath();
    if (cookiePath != null) {
      cookie.setPath(cookiePath);
    }

    if (expiryMins > 0) {
      cookie.setMaxAge(expiryMins * 60);
    }

    context.getResponse().getCookies().add(cookie);
  }
View Full Code Here

            Boolean secure = (Boolean) m.get("secure");
            String comment = (String) m.get("comment");
            String commentUrl = (String) m.get("commentUrl");
            List<Integer> ports = (List<Integer>) m.get("ports");
            DateTime ts = timestamp == null ? DateTime.now() : new DateTime(timestamp.longValue());
            DateCookie cookie = new DateCookie(new DefaultCookie(name, value), ts);
            if (cookie.isExpired()) {
                continue;
            }
            if (domain != null) {
                cookie.setDomain(domain);
View Full Code Here

    @Test
    public void test() throws IOException {
        assertTrue(true);
        CookieStore store = new CookieStore();
        DefaultCookie ck1 = new DefaultCookie("foo", "bar");
        DefaultCookie ck2 = new DefaultCookie("one", "two");
        ck1.setPath("/foo");
        ck1.setDomain("foo.com");
        ck1.setMaxAge(10000);

        ck2.setPath("/foo");
        ck2.setDomain("foo.com");
        ck2.setMaxAge(10000);

        DefaultFullHttpResponse resp = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
        resp.headers().add(Headers.SET_COOKIE.name(), Headers.SET_COOKIE.toString(ck1));
        resp.headers().add(Headers.SET_COOKIE.name(), Headers.SET_COOKIE.toString(ck2));

        store.extract(resp.headers());
        Iterator<Cookie> iter = store.iterator();
        assertTrue(iter.hasNext());
        assertTrue(iter.hasNext());

        HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/foo/bar");
        req.headers().add(Headers.HOST.name(), "foo.com");
        store.decorate(req);

        List<String> cookieHeaders = req.headers().getAll(Headers.COOKIE.name());
        System.out.println("COOKIE HEADERS: " + cookieHeaders);
        assertEquals(2, cookieHeaders.size());

        List<String> find = new LinkedList<>(Arrays.asList("foo", "one"));
        for (String hdr : cookieHeaders) {
            Cookie cookie = Headers.SET_COOKIE.toValue(hdr);
            find.remove(cookie.getName());
        }
        assertTrue("Not found: " + find, find.isEmpty());

        CookieStore nue = new CookieStore(store.cookies, true, true);
        assertEquals(store, nue);

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        store.store(out);
        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
        nue = new CookieStore();
        nue.read(in);
        assertEquals(store, nue);

        DefaultCookie ck3 = new DefaultCookie("fuz", "bang");
        ck3.setMaxAge(20000);
        ck3.setPath("/moo/wuzz");
        ck3.setDomain("foo.com");
        nue.add(ck3);
        assertNotEquals(store, nue);
    }
View Full Code Here

                        int ival = Integer.parseInt(val) + 1;
                        value = Integer.toString(ival);
                    }
                }
            }
            DefaultCookie ck = new DefaultCookie("xid", value);
            ck.setMaxAge(500);
            ck.setPath("/ok");
            add(Headers.SET_COOKIE, ck);
            setState(new ConsumedLockedState());
        }
View Full Code Here

TOP

Related Classes of io.netty.handler.codec.http.DefaultCookie

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.