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

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

Introduction

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

Prototype

void setMaxAge(long maxAge);

Source Link

Document

Sets the maximum age of this Cookie in seconds.

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);//  www  .  j ava 2s .  c om
    cookie.setPath("/");
    cookie.setMaxAge(maxAge);
    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);/*from w w w  .  ja va2  s .c  o  m*/
    cookie.setPath("/");
    cookie.setMaxAge(maxAge);
    response.addCookie(cookie);
}

From source file:com.bay1ts.bay.core.Response.java

License:Apache License

/**
 * Adds cookie to the response. Can be invoked multiple times to insert more than one cookie.
 *
 * @param path     path of the cookie/*from w ww.ja  va2 s . c  o  m*/
 * @param name     name of the cookie
 * @param value    value of the cookie
 * @param maxAge   max age of the cookie in seconds (negative for the not persistent cookie, zero - deletes the cookie)
 * @param secured  if true : cookie will be secured
 * @param httpOnly if true: cookie will be marked as http only
 */
public void cookie(String path, String name, String value, int maxAge, boolean secured, boolean httpOnly) {
    Cookie cookie = new DefaultCookie(name, value);
    cookie.setPath(path);
    cookie.setMaxAge(maxAge);
    cookie.setSecure(secured);
    cookie.setHttpOnly(httpOnly);
    response.headers().set(HttpHeaderNames.COOKIE, ServerCookieEncoder.STRICT.encode(cookie));
}

From source file:nikoladasm.aspark.ResponseImpl.java

License:Open Source License

@Override
public void cookie(String path, String name, String value, int maxAge, boolean secured, boolean httpOnly) {
    Cookie cookie = new DefaultCookie(name, value);
    cookie.setPath(path);//from w  w w. j ava2s .  c om
    cookie.setMaxAge(maxAge);
    cookie.setSecure(secured);
    cookie.setHttpOnly(httpOnly);
    cookies.put(name, cookie);
}

From source file:nikoladasm.aspark.ResponseImpl.java

License:Open Source License

@Override
public void removeCookie(String name) {
    Cookie cookie = new DefaultCookie(name, "");
    cookie.setMaxAge(0);
    cookies.put(name, cookie);//from  w  w  w .j a v a 2  s .c o m
}

From source file:org.glowroot.ui.HttpSessionManager.java

License:Apache License

void deleteSessionCookie(CommonResponse response) throws Exception {
    Cookie cookie = new DefaultCookie(configRepository.getWebConfig().sessionCookieName(), "");
    cookie.setHttpOnly(true);//from   w  w w. j av a 2 s .co m
    cookie.setMaxAge(0);
    cookie.setPath("/");
    response.setHeader(HttpHeaderNames.SET_COOKIE, ServerCookieEncoder.STRICT.encode(cookie));
}

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

License:Apache License

/**
 * Create a Netty representation of a cookie.
 *
 * @param cookie//  ww w . jav  a2 s  . 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 ww w  .  j  a va2  s .  co  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:org.springframework.http.server.reactive.RxNettyServerHttpResponse.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());
            }/*ww  w  .j  ava 2  s. c o m*/
            httpCookie.getDomain().ifPresent(cookie::setDomain);
            httpCookie.getPath().ifPresent(cookie::setPath);
            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 addCookie(String name, String value) {
    Cookie cookie = response.get().cookie(name, value);
    if (cookieConfig.getPath() != null) {
        cookie.setPath(cookieConfig.getPath());
    }/*from  w w w.  j a  va  2s .  co m*/
    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());
}