List of usage examples for io.netty.handler.codec.http.cookie DefaultCookie setSecure
@Override public void setSecure(boolean secure)
From source file:gribbit.http.response.Response.java
License:Open Source License
/** * Set a cookie in the response./*from w w w. ja va2 s .com*/ * * (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
protected void sendHeaders(RoutingContext routingContext, String contentType) { HttpServerRequest request = routingContext.request(); HttpServerResponse response = request.response(); MultiMap headers = response.headers(); headers.add("Content-Type", contentType); if (customHeaders != null) { for (CustomHeader c : customHeaders) { headers.add(c.key, c.value); }/* www . j a v a2s.c o m*/ } if (cookies != null) { for (DefaultCookie cookie : cookies.values()) { // If the request is over SSL, set the cookie to be only visible over SSL cookie.setSecure(request.isSSL()); routingContext.addCookie(Cookie.cookie(cookie)); } } if (logOut) { User.logOut(routingContext.session()); } }
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()); }//from w ww.j a v a2 s. c o m 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 w w w . j a va 2 s. c om*/ } 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); }