Example usage for io.netty.handler.codec.http.cookie Cookie setDomain

List of usage examples for io.netty.handler.codec.http.cookie Cookie setDomain

Introduction

In this page you can find the example usage for io.netty.handler.codec.http.cookie Cookie setDomain.

Prototype

void setDomain(String domain);

Source Link

Document

Sets the domain of this Cookie .

Usage

From source file:cn.wantedonline.puppy.httpserver.httptools.CookieHelper.java

License:Apache License

public static void addCookie(String key, String value, int maxAge, HttpResponse response) {
    Cookie cookie = new DefaultCookie(key, value);
    cookie.setDomain(domain);
    cookie.setPath("/");
    cookie.setMaxAge(maxAge);/*from ww w.  j  a v a2s  .  co m*/
    response.addCookie(cookie);
}

From source file:cn.wantedonline.puppy.httpserver.httptools.CookieHelper.java

License:Apache License

public static void addSessionCookie(String sessionId, int maxAge, HttpResponse response) {
    Cookie cookie = new DefaultCookie(HttpServerConfig.SESSIONID_PARAMERTER, sessionId);
    cookie.setDomain(domain);
    cookie.setPath("/");
    cookie.setMaxAge(maxAge);//from  w ww. j av a 2  s.  c o m
    response.addCookie(cookie);
}

From source file:io.vertx.ext.web.client.SessionAwareWebClientTest.java

License:Open Source License

@Test
public void testCookieStore(TestContext context) {
    CookieStore store = CookieStore.build();
    Cookie c;

    c = new DefaultCookie("a", "1");
    store.put(c);/*w  w w.ja va  2s. co m*/

    c = new DefaultCookie("b", "2");
    c.setDomain("vertx.io");
    store.put(c);

    c = new DefaultCookie("c", "3");
    c.setDomain("www.vertx.io");
    c.setPath("/web-client");
    store.put(c);

    c = new DefaultCookie("d", "4");
    c.setPath("/web-client");
    store.put(c);

    c = new DefaultCookie("e", "5");
    c.setDomain("vertx.io");
    c.setSecure(true);
    store.put(c);

    c = new DefaultCookie("b", "20");
    c.setDomain("www.vertx.io");
    store.put(c);

    c = new DefaultCookie("b", "200");
    c.setDomain("www.vertx.io");
    c.setPath("/web-client");
    store.put(c);

    validate(context, store.get(false, "www.vertx.io", "/"), new String[] { "a", "b" },
            new String[] { "1", "20" });
    validate(context, store.get(false, "a.www.vertx.io", "/"), new String[] { "a", "b" },
            new String[] { "1", "20" });
    validate(context, store.get(false, "test.vertx.io", "/"), new String[] { "a", "b" },
            new String[] { "1", "2" });
    validate(context, store.get(false, "www.vertx.io", "/web-client"), new String[] { "a", "b", "c", "d" },
            new String[] { "1", "200", "3", "4" });
    validate(context, store.get(true, "test.vertx.io", "/"), new String[] { "a", "b", "e" },
            new String[] { "1", "2", "5" });
}

From source file:org.robotbrains.support.web.server.netty.NettyHttpResponse.java

License:Apache License

/**
 * Create a Netty representation of a cookie.
 *
 * @param cookie//from  ww  w  .j  av  a 2s . co m
 *          the standard Java cookie
 *
 * @return the Netty cookie
 */
public static Cookie createNettyCookie(HttpCookie cookie) {
    Cookie nettyCookie = new DefaultCookie(cookie.getName(), cookie.getValue());
    nettyCookie.setDomain(cookie.getDomain());
    nettyCookie.setMaxAge((int) cookie.getMaxAge());
    nettyCookie.setPath(cookie.getPath());
    nettyCookie.setSecure(cookie.getSecure());

    return nettyCookie;
}

From source file:org.springframework.http.server.reactive.ReactorServerHttpResponse.java

License:Apache License

@Override
protected void applyCookies() {
    for (String name : getCookies().keySet()) {
        for (ResponseCookie httpCookie : getCookies().get(name)) {
            Cookie cookie = new DefaultCookie(name, httpCookie.getValue());
            if (!httpCookie.getMaxAge().isNegative()) {
                cookie.setMaxAge(httpCookie.getMaxAge().getSeconds());
            }//from  w w w . j  a  v a  2 s .c  o m
            if (httpCookie.getDomain() != null) {
                cookie.setDomain(httpCookie.getDomain());
            }
            if (httpCookie.getPath() != null) {
                cookie.setPath(httpCookie.getPath());
            }
            cookie.setSecure(httpCookie.isSecure());
            cookie.setHttpOnly(httpCookie.isHttpOnly());
            this.response.addCookie(cookie);
        }
    }
}

From source file:ratpack.session.clientside.internal.ClientSideSessionStore.java

License:Apache License

private void invalidateCookie(String name) {
    Cookie cookie = response.get().expireCookie(name);
    if (cookieConfig.getPath() != null) {
        cookie.setPath(cookieConfig.getPath());
    }/*  w w  w .  ja  v a  2 s  . c  o m*/
    if (cookieConfig.getDomain() != null) {
        cookie.setDomain(cookieConfig.getDomain());
    }
    cookie.setHttpOnly(cookieConfig.isHttpOnly());
    cookie.setSecure(cookieConfig.isSecure());
}

From source file:ratpack.session.clientside.internal.ClientSideSessionStore.java

License:Apache License

private void addCookie(String name, String value) {
    Cookie cookie = response.get().cookie(name, value);
    if (cookieConfig.getPath() != null) {
        cookie.setPath(cookieConfig.getPath());
    }//from   ww  w  .  ja v a 2 s .c om
    if (cookieConfig.getDomain() != null) {
        cookie.setDomain(cookieConfig.getDomain());
    }

    long expirySeconds = cookieConfig.getExpires() == null ? 0 : cookieConfig.getExpires().getSeconds();
    if (expirySeconds > 0) {
        cookie.setMaxAge(expirySeconds);
    }
    cookie.setHttpOnly(cookieConfig.isHttpOnly());
    cookie.setSecure(cookieConfig.isSecure());
}