Java Code Examples for io.netty.handler.codec.http.cookie.Cookie#setMaxAge()
The following examples show how to use
io.netty.handler.codec.http.cookie.Cookie#setMaxAge() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReactorServerHttpResponse.java From spring-analysis-note with MIT License | 6 votes |
@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()); } 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); } } }
Example 2
Source File: ReactorServerHttpResponse.java From java-technology-stack with MIT License | 6 votes |
@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()); } 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); } } }
Example 3
Source File: ResponseSenderTest.java From riposte with Apache License 2.0 | 6 votes |
private Set<Cookie> createCookies(int numberOfCookies) { if (numberOfCookies < 0) { return null; } Set<Cookie> cookies = new HashSet<>(); for (int x = 0; x < numberOfCookies; x++) { Cookie cookie = new DefaultCookie(UUID.randomUUID().toString(), UUID.randomUUID().toString()); cookie.setHttpOnly(new Random().ints(0, 1000).findAny().getAsInt() % 2 == 0); cookie.setMaxAge(new Random().longs(0, 1000).findAny().getAsLong()); cookies.add(cookie); } return cookies; }
Example 4
Source File: DefaultWebRes.java From krpc with Apache License 2.0 | 5 votes |
public DefaultWebRes addCookie(String name, String value) { String paramsStr = null; int p = value.indexOf("^"); if (p >= 0) { paramsStr = value.substring(p + 1); value = value.substring(0, p); } if (cookies == null) cookies = new ArrayList<>(); Cookie c = new DefaultCookie(name, value); if (paramsStr != null) { Map<String, String> params = Plugin.defaultSplitParams(paramsStr); if (params.containsKey("domain")) c.setDomain(params.get("domain")); if (params.containsKey("path")) c.setPath(params.get("path")); if (params.containsKey("maxAge")) c.setMaxAge(Long.parseLong(params.get("maxAge"))); if (params.containsKey("httpOnly")) c.setHttpOnly(Boolean.parseBoolean(params.get("httpOnly"))); else c.setHttpOnly(true); if (params.containsKey("secure")) c.setSecure(Boolean.parseBoolean(params.get("secure"))); if (params.containsKey("wrap")) c.setWrap(Boolean.parseBoolean(params.get("wrap"))); } cookies.add(c); return this; }
Example 5
Source File: DefaultCookieManager.java From redant with Apache License 2.0 | 5 votes |
@Override public void addCookie(String name, String value, String domain, long maxAge) { if (StrUtil.isNotBlank(name) && StrUtil.isNotBlank(value)) { Cookie cookie = new DefaultCookie(name, value); cookie.setPath("/"); if (domain != null && domain.trim().length() > 0) { cookie.setDomain(domain); } if (maxAge > 0) { cookie.setMaxAge(maxAge); } setCookie(cookie); } }
Example 6
Source File: DefaultCookieManager.java From redant with Apache License 2.0 | 5 votes |
@Override public boolean deleteCookie(String name) { Cookie cookie = getCookie(name); if (cookie != null) { cookie.setMaxAge(0); cookie.setPath("/"); setCookie(cookie); return true; } return false; }
Example 7
Source File: HttpResponse.java From blade with Apache License 2.0 | 5 votes |
@Override public Response cookie(@NonNull String name, @NonNull String value, int maxAge) { Cookie nettyCookie = new io.netty.handler.codec.http.cookie.DefaultCookie(name, value); nettyCookie.setPath("/"); nettyCookie.setMaxAge(maxAge); this.cookies.add(nettyCookie); return this; }
Example 8
Source File: HttpResponse.java From blade with Apache License 2.0 | 5 votes |
@Override public Response cookie(@NonNull String name, @NonNull String value, int maxAge, boolean secured) { Cookie nettyCookie = new io.netty.handler.codec.http.cookie.DefaultCookie(name, value); nettyCookie.setPath("/"); nettyCookie.setMaxAge(maxAge); nettyCookie.setSecure(secured); this.cookies.add(nettyCookie); return this; }
Example 9
Source File: HttpResponse.java From blade with Apache License 2.0 | 5 votes |
@Override public Response cookie(@NonNull String path, @NonNull String name, @NonNull String value, int maxAge, boolean secured) { Cookie nettyCookie = new io.netty.handler.codec.http.cookie.DefaultCookie(name, value); nettyCookie.setMaxAge(maxAge); nettyCookie.setSecure(secured); nettyCookie.setPath(path); this.cookies.add(nettyCookie); return this; }
Example 10
Source File: HttpResponse.java From blade with Apache License 2.0 | 5 votes |
@Override public Response removeCookie(@NonNull String name) { Optional<Cookie> cookieOpt = this.cookies.stream().filter(cookie -> cookie.name().equals(name)).findFirst(); cookieOpt.ifPresent(cookie -> { cookie.setValue(""); cookie.setMaxAge(-1); }); Cookie nettyCookie = new io.netty.handler.codec.http.cookie.DefaultCookie(name, ""); nettyCookie.setMaxAge(-1); this.cookies.add(nettyCookie); return this; }
Example 11
Source File: HttpSessionManager.java From glowroot with Apache License 2.0 | 5 votes |
void deleteSessionCookie(CommonResponse response) throws Exception { Cookie cookie = new DefaultCookie(configRepository.getWebConfig().sessionCookieName(), ""); cookie.setHttpOnly(true); cookie.setMaxAge(0); cookie.setPath("/"); response.setHeader(HttpHeaderNames.SET_COOKIE, ServerCookieEncoder.STRICT.encode(cookie)); }