@Override public RoutingContext addCookie(Cookie cookie) { cookiesMap().put(cookie.getName(), cookie); return this; }
@Override public Cookie[] getCookies() { if (cookies == null) { Set<io.vertx.ext.web.Cookie> vertxCookies = context.cookies(); Cookie tmpCookies[] = new Cookie[vertxCookies.size()]; int idx = 0; for (io.vertx.ext.web.Cookie oneVertxCookie : vertxCookies) { Cookie cookie = new Cookie(oneVertxCookie.getName(), oneVertxCookie.getValue()); tmpCookies[idx] = cookie; idx++; } cookies = tmpCookies; } return cookies; }
private boolean contains(Set<Cookie> cookies, String name) { for (Cookie cookie: cookies) { if (cookie.getName().equals(name)) { return true; } } return false; }
@Override public String getFormattedItem(AccessLogParam<RoutingContext> accessLogParam) { Set<Cookie> cookieSet = accessLogParam.getContextData().cookies(); if (null == cookieSet) { return RESULT_NOT_FOUND; } String result = null; for (Cookie cookie : cookieSet) { if (varName.equals(cookie.getName())) { result = cookie.getValue(); } } if (null == result) { return RESULT_NOT_FOUND; } return result; }
/** * @return the name of this cookie */ public String getName() { String ret = delegate.getName(); return ret; }
/** * @return the name of this cookie */ public String getName() { String ret = delegate.getName(); return ret; }
@Override public RoutingContext addCookie(Cookie cookie) { cookiesMap().put(cookie.getName(), cookie); return this; }
private boolean contains(Set<Cookie> cookies, String name) { for (Cookie cookie: cookies) { if (cookie.getName().equals(name)) { return true; } } return false; }
@Test public void testCookieFields() throws Exception { Cookie cookie = Cookie.cookie("foo", "bar"); assertEquals("foo", cookie.getName()); assertEquals("bar", cookie.getValue()); assertEquals("foo=bar", cookie.encode()); assertNull(cookie.getPath()); cookie.setPath("/somepath"); assertEquals("/somepath", cookie.getPath()); assertEquals("foo=bar; Path=/somepath", cookie.encode()); assertNull(cookie.getDomain()); cookie.setDomain("foo.com"); assertEquals("foo.com", cookie.getDomain()); assertEquals("foo=bar; Path=/somepath; Domain=foo.com", cookie.encode()); long maxAge = 30 * 60; cookie.setMaxAge(maxAge); long now = System.currentTimeMillis(); String encoded = cookie.encode(); int startPos = encoded.indexOf("Expires="); int endPos = encoded.indexOf(';', startPos); String expiresDate = encoded.substring(startPos + 8, endPos); Date d = dateTimeFormat.parse(expiresDate); assertTrue(d.getTime() - now >= maxAge); cookie.setMaxAge(Long.MIN_VALUE); cookie.setSecure(true); assertEquals("foo=bar; Path=/somepath; Domain=foo.com; Secure", cookie.encode()); cookie.setHttpOnly(true); assertEquals("foo=bar; Path=/somepath; Domain=foo.com; Secure; HTTPOnly", cookie.encode()); }
@Override public Cookie[] getCookies() { if (cookies == null) { Set<io.vertx.ext.web.Cookie> vertxCookies = context.cookies(); Cookie tmpCookies[] = new Cookie[vertxCookies.size()]; int idx = 0; for (io.vertx.ext.web.Cookie oneVertxCookie : vertxCookies) { Cookie cookie = new Cookie(oneVertxCookie.getName(), oneVertxCookie.getValue()); tmpCookies[idx] = cookie; idx++; } cookies = tmpCookies; } return cookies; }
@Override public Cookie[] getCookies() { if (cookies == null) { Set<io.vertx.ext.web.Cookie> vertxCookies = context.cookies(); Cookie tmpCookies[] = new Cookie[vertxCookies.size()]; int idx = 0; for (io.vertx.ext.web.Cookie oneVertxCookie : vertxCookies) { Cookie cookie = new Cookie(oneVertxCookie.getName(), oneVertxCookie.getValue()); tmpCookies[idx] = cookie; idx++; } cookies = tmpCookies; } return cookies; }
@Override public String getFormattedItem(AccessLogParam<RoutingContext> accessLogParam) { Set<Cookie> cookieSet = accessLogParam.getContextData().cookies(); if (null == cookieSet) { return RESULT_NOT_FOUND; } String result = null; for (Cookie cookie : cookieSet) { if (varName.equals(cookie.getName())) { result = cookie.getValue(); } } if (null == result) { return RESULT_NOT_FOUND; } return result; }
@Override public Collection<Cookie> getRequestCookies() { return routingContext.cookies().stream().map(cookie -> { final Cookie p4jCookie = new Cookie(cookie.getName(), cookie.getValue()); p4jCookie.setDomain(cookie.getDomain()); p4jCookie.setPath(cookie.getPath()); return p4jCookie; }).collect(Collectors.toList()); }
@Override public Collection<Cookie> getRequestCookies() { return routingContext.cookies().stream().map(cookie -> { final Cookie p4jCookie = new Cookie(cookie.getName(), cookie.getValue()); p4jCookie.setDomain(cookie.getDomain()); p4jCookie.setPath(cookie.getPath()); return p4jCookie; }).collect(Collectors.toList()); }
@Test public void testCookieFields() throws Exception { Cookie cookie = Cookie.cookie("foo", "bar"); assertEquals("foo", cookie.getName()); assertEquals("bar", cookie.getValue()); assertEquals("foo=bar", cookie.encode()); assertNull(cookie.getPath()); cookie.setPath("/somepath"); assertEquals("/somepath", cookie.getPath()); assertEquals("foo=bar; Path=/somepath", cookie.encode()); assertNull(cookie.getDomain()); cookie.setDomain("foo.com"); assertEquals("foo.com", cookie.getDomain()); assertEquals("foo=bar; Path=/somepath; Domain=foo.com", cookie.encode()); long maxAge = 30 * 60; cookie.setMaxAge(maxAge); long now = System.currentTimeMillis(); String encoded = cookie.encode(); int startPos = encoded.indexOf("Expires="); int endPos = encoded.indexOf(';', startPos); String expiresDate = encoded.substring(startPos + 8, endPos); Date d = dateTimeFormat.parse(expiresDate); assertTrue(d.getTime() - now >= maxAge); cookie.setMaxAge(Long.MIN_VALUE); cookie.setSecure(true); assertEquals("foo=bar; Path=/somepath; Domain=foo.com; Secure", cookie.encode()); cookie.setHttpOnly(true); assertEquals("foo=bar; Path=/somepath; Domain=foo.com; Secure; HTTPOnly", cookie.encode()); }