Example usage for io.netty.handler.codec.http.cookie DefaultCookie setPath

List of usage examples for io.netty.handler.codec.http.cookie DefaultCookie setPath

Introduction

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

Prototype

@Override
    public void setPath(String path) 

Source Link

Usage

From source file:gribbit.http.response.Response.java

License:Open Source License

/**
 * Set a cookie in the response./*  www  . ja v a 2 s .  c o  m*/
 * 
 * (As per RFC6295, the server can only return one cookie with a given name per response. We arbitrarily choose
 * the last value the cookie is set to as the one that is sent in the response, even if setCookie is called
 * multiple times for a given cookie name with different paths.)
 * 
 * If the request was made over HTTPS, then the cookie is also set to be visible only over HTTPS.
 * 
 * @param name
 *            The name of the cookie.
 * @param path
 *            The path, or if null, defaults (in the browser) to the path of the request.
 * @param value
 *            The value of the cookie.
 * @param maxAgeSeconds
 *            The max age of the cookie. If 0, causes the cookie to be deleted. If negative, causes the cookie
 *            to "never" expire (actually sets expiration date to a year from now).
 * @param httpOnly
 *            If true, cookie is inaccessible to Javascript.
 */
public Response setCookie(String name, String value, String path, long maxAgeSeconds, boolean httpOnly) {
    DefaultCookie cookie = new DefaultCookie(name, value);
    if (path != null) {
        cookie.setPath(path);
    }
    cookie.setMaxAge(maxAgeSeconds < 0 ? ONE_YEAR_IN_SECONDS : maxAgeSeconds);
    cookie.setHttpOnly(httpOnly);
    if (request.isSecure()) {
        cookie.setSecure(true);
    }
    return setCookie(cookie);
}

From source file:gribbit.response.Response.java

License:Open Source License

/**
 * Set a cookie in the response./* w  ww.j av a 2 s  .  c om*/
 * 
 * (As per RFC6295, the server can only return one cookie with a given name per response. We arbitrarily choose
 * the last value the cookie is set to as the one that is sent in the response, even if setCookie is called
 * multiple times for a given cookie name with different paths.)
 * 
 * If the request was made over HTTPS, then the cookie is also set to be visible only over HTTPS.
 * 
 * @param name
 *            The name of the cookie.
 * @param path
 *            The path, or if null, defaults (in the browser) to the path of the request.
 * @param value
 *            The value of the cookie.
 * @param maxAgeSeconds
 *            The max age of the cookie. If 0, causes the cookie to be deleted. If negative, causes the cookie
 *            to "never" expire (actually sets expiration date to a year from now).
 * @param httpOnly
 *            If true, cookie is inaccessible to Javascript. (Recommended.)
 */
public Response setCookie(String name, String value, String path, long maxAgeSeconds, boolean httpOnly) {
    DefaultCookie cookie = new DefaultCookie(name, value);
    if (path != null) {
        cookie.setPath(path);
    }
    long ONE_YEAR_IN_SECONDS = 31536000L;
    cookie.setMaxAge(maxAgeSeconds < 0 ? ONE_YEAR_IN_SECONDS : maxAgeSeconds);
    cookie.setHttpOnly(httpOnly);
    setCookie(cookie);
    return this;
}

From source file:ratpack.pac4j.internal.RatpackWebContext.java

License:Apache License

@Override
public void addResponseCookie(Cookie cookie) {
    final DefaultCookie newCookie = new DefaultCookie(cookie.getName(), cookie.getValue());
    newCookie.setDomain(cookie.getDomain());
    newCookie.setPath(cookie.getPath());
    if (cookie.getMaxAge() >= 0) {
        newCookie.setMaxAge(cookie.getMaxAge());
    }/*  ww  w  .  ja v  a2s  .  com*/
    newCookie.setSecure(cookie.isSecure());
    newCookie.setHttpOnly(cookie.isHttpOnly());
    response.getCookies().add(newCookie);
}

From source file:ratpack.session.internal.CookieBasedSessionId.java

License:Apache License

private void setCookie(String value, Duration expiration) {
    DefaultCookie cookie = new DefaultCookie(cookieConfig.getIdName(), value);

    String cookieDomain = cookieConfig.getDomain();
    if (cookieDomain != null) {
        cookie.setDomain(cookieDomain);/*from ww  w  . j  a v a 2 s . com*/
    }

    String cookiePath = cookieConfig.getPath();
    if (cookiePath != null) {
        cookie.setPath(cookiePath);
    }

    long expirySeconds = expiration == null ? 0 : expiration.getSeconds();
    if (expirySeconds > 0) {
        cookie.setMaxAge(expirySeconds);
    }

    cookie.setHttpOnly(cookieConfig.isHttpOnly());

    cookie.setSecure(cookieConfig.isSecure());

    response.getCookies().add(cookie);
}