List of usage examples for io.netty.handler.codec.http.cookie Cookie path
String path();
From source file:gribbit.http.response.Response.java
License:Open Source License
/** * Look through the request for cookies with the given name, and delete any matches in the response. (i.e. can * only delete cookies that are actually visible in the request.) Note that per RFC6295, the client should be * sending cookies in order of decreasing path length, and also the server can only send one Set-Cookie header * per cookie name, so if there are multiple matches, only the last match (the one with the shortest path) will * be deleted when the response is set, and you'll need to return multiple responses with the same deleteCookie * action applied to delete them all.//from w w w .j av a2 s . c o m */ public Response deleteCookie(String cookieName) { ArrayList<Cookie> reqCookies = request.getCookies(cookieName); if (reqCookies != null) { Cookie firstCookie = reqCookies.iterator().next(); setCookie(firstCookie.name(), /* value = */"", /* path = */firstCookie.path(), /* maxAgeSeconds = */ 0, /* httpOnly = */false); } return this; }
From source file:io.vertx.ext.web.client.impl.CookieStoreImpl.java
License:Open Source License
@Override public Iterable<Cookie> get(Boolean ssl, String domain, String path) { assert domain != null && domain.length() > 0; String cleanPath;/*from w w w.java2s.c o m*/ { String uri = HttpUtils.removeDots(path); // Remoe query params if present int pos = uri.indexOf('?'); if (pos > -1) { uri = uri.substring(0, pos); } // Remoe frament identifier if present pos = uri.indexOf('#'); if (pos > -1) { uri = uri.substring(0, pos); } cleanPath = uri; } TreeMap<String, Cookie> matches = new TreeMap<>(); Consumer<Cookie> adder = c -> { if (ssl != Boolean.TRUE && c.isSecure()) { return; } if (c.path() != null && !cleanPath.equals(c.path())) { String cookiePath = c.path(); if (!cookiePath.endsWith("/")) { cookiePath += '/'; } if (!cleanPath.startsWith(cookiePath)) { return; } } matches.put(c.name(), c); }; for (Cookie c : noDomainCookies.values()) { adder.accept(c); } Key key = new Key(domain, "", ""); String prefix = key.domain.substring(0, 1); for (Entry<Key, Cookie> entry : domainCookies.tailMap(new Key(prefix, "", ""), true).entrySet()) { if (entry.getKey().domain.compareTo(key.domain) > 0) { break; } if (!key.domain.startsWith(entry.getKey().domain)) { continue; } adder.accept(entry.getValue()); } return matches.values(); }
From source file:io.vertx.ext.web.client.impl.CookieStoreImpl.java
License:Open Source License
@Override public CookieStore put(Cookie cookie) { Key key = new Key(cookie.domain(), cookie.path(), cookie.name()); if (key.domain.equals(Key.NO_DOMAIN)) { noDomainCookies.put(key, cookie); return this; }//w ww . ja va 2 s. co m domainCookies.put(key, cookie); return this; }
From source file:io.vertx.ext.web.client.impl.CookieStoreImpl.java
License:Open Source License
@Override public CookieStore remove(Cookie cookie) { Key key = new Key(cookie.domain(), cookie.path(), cookie.name()); if (key.domain.equals(Key.NO_DOMAIN)) { noDomainCookies.remove(key);/*from w w w . ja v a 2s . co m*/ } else { domainCookies.remove(key); } return this; }
From source file:org.asynchttpclient.cookie.ThreadSafeCookieStore.java
License:Open Source License
private void add(String requestDomain, String requestPath, Cookie cookie) { AbstractMap.SimpleEntry<String, Boolean> pair = cookieDomain(cookie.domain(), requestDomain); String keyDomain = pair.getKey(); boolean hostOnly = pair.getValue(); String keyPath = cookiePath(cookie.path(), requestPath); CookieKey key = new CookieKey(cookie.name().toLowerCase(), keyDomain, keyPath); if (hasCookieExpired(cookie, 0)) cookieJar.remove(key);/* w ww.j a v a2s . com*/ else cookieJar.put(key, new StoredCookie(cookie, hostOnly, cookie.maxAge() != Cookie.UNDEFINED_MAX_AGE)); }
From source file:org.atmosphere.nettosphere.BridgeRuntime.java
License:Apache License
private Set<javax.servlet.http.Cookie> getCookies(final HttpRequest request) { Set<javax.servlet.http.Cookie> result = new HashSet<javax.servlet.http.Cookie>(); String cookieHeader = request.headers().get("Cookie"); if (cookieHeader != null) { Set<io.netty.handler.codec.http.cookie.Cookie> cookies = ServerCookieDecoder.LAX.decode(cookieHeader); for (io.netty.handler.codec.http.cookie.Cookie cookie : cookies) { javax.servlet.http.Cookie c = new javax.servlet.http.Cookie(cookie.name(), cookie.value()); if (cookie.domain() != null) { c.setDomain(cookie.domain()); }// w ww .jav a2s .c o m c.setHttpOnly(cookie.isHttpOnly()); c.setMaxAge((int) cookie.maxAge()); if (cookie.path() != null) { c.setPath(cookie.path()); } c.setSecure(cookie.isSecure()); result.add(c); } } return result; }
From source file:org.jooby.internal.netty.NettyRequest.java
License:Apache License
private org.jooby.Cookie cookie(final Cookie c) { org.jooby.Cookie.Definition cookie = new org.jooby.Cookie.Definition(c.name(), c.value()); Optional.ofNullable(c.domain()).ifPresent(cookie::domain); Optional.ofNullable(c.path()).ifPresent(cookie::path); return cookie.toCookie(); }
From source file:org.robotbrains.support.web.server.netty.NettyHttpRequest.java
License:Apache License
/** * Convert a Netty cookie to a Java HTTP cookie. * * @param cookie//from w w w.ja v a 2 s . c om * the Netty cookie * * @return the Java cookie */ private HttpCookie convertFromNettyCookie(Cookie cookie) { HttpCookie httpCookie = new HttpCookie(cookie.name(), cookie.value()); httpCookie.setDomain(cookie.domain()); httpCookie.setMaxAge(cookie.maxAge()); httpCookie.setPath(cookie.path()); httpCookie.setSecure(cookie.isSecure()); return httpCookie; }