private void createNewSession(RoutingContext context) { Session session = sessionStore.createSession(sessionTimeout, minLength); context.setSession(session); Cookie cookie = Cookie.cookie(sessionCookieName, session.value()); cookie.setPath(sessionCookiePath); cookie.setSecure(sessionCookieSecure); cookie.setHttpOnly(sessionCookieHttpOnly); // Don't set max age - it's a session cookie context.addCookie(cookie); addStoreSessionHandler(context); } }
/** * The short representation of the session to be added to the session cookie. By default is the session id. * @return short representation string. */ public String value() { String ret = delegate.value(); return ret; }
/** * The short representation of the session to be added to the session cookie. By default is the session id. * @return short representation string. */ public String value() { String ret = delegate.value(); return ret; }
cookie.setValue(session.value()).setPath("/").setSecure(sessionCookieSecure) .setHttpOnly(sessionCookieHttpOnly);
@Test public void testSessionFields() throws Exception { router.route().handler(CookieHandler.create()); router.route().handler(SessionHandler.create(store)); AtomicReference<String> rid = new AtomicReference<>(); router.route().handler(rc -> { Session sess = rc.session(); assertNotNull(sess); assertTrue(System.currentTimeMillis() - sess.lastAccessed() < 500); assertNotNull(sess.id()); rid.set(sess.value()); assertFalse(sess.isDestroyed()); assertEquals(SessionHandler.DEFAULT_SESSION_TIMEOUT, sess.timeout()); rc.response().end(); }); testRequest(HttpMethod.GET, "/", null, resp -> { String setCookie = resp.headers().get("set-cookie"); assertTrue(setCookie.startsWith(SessionHandler.DEFAULT_SESSION_COOKIE_NAME + "=")); int pos = setCookie.indexOf("; Path=" + SessionHandler.DEFAULT_SESSION_COOKIE_PATH); String sessID = setCookie.substring(18, pos); assertEquals(rid.get(), sessID); }, 200, "OK", null); }
private void createNewSession(RoutingContext context) { Session session = sessionStore.createSession(sessionTimeout, minLength); context.setSession(session); Cookie cookie = Cookie.cookie(sessionCookieName, session.value()); cookie.setPath(sessionCookiePath); cookie.setSecure(sessionCookieSecure); cookie.setHttpOnly(sessionCookieHttpOnly); // Don't set max age - it's a session cookie context.addCookie(cookie); addStoreSessionHandler(context); } }
cookie.setValue(session.value()).setPath("/").setSecure(sessionCookieSecure) .setHttpOnly(sessionCookieHttpOnly);
@Test public void testSessionFields() throws Exception { router.route().handler(CookieHandler.create()); router.route().handler(SessionHandler.create(store)); AtomicReference<String> rid = new AtomicReference<>(); router.route().handler(rc -> { Session sess = rc.session(); assertNotNull(sess); assertTrue(System.currentTimeMillis() - sess.lastAccessed() < 500); assertNotNull(sess.id()); rid.set(sess.value()); assertFalse(sess.isDestroyed()); assertEquals(SessionHandler.DEFAULT_SESSION_TIMEOUT, sess.timeout()); rc.response().end(); }); testRequest(HttpMethod.GET, "/", null, resp -> { String setCookie = resp.headers().get("set-cookie"); assertTrue(setCookie.startsWith(SessionHandler.DEFAULT_SESSION_COOKIE_NAME + "=")); int pos = setCookie.indexOf("; Path=" + SessionHandler.DEFAULT_SESSION_COOKIE_PATH); String sessID = setCookie.substring(18, pos); assertEquals(rid.get(), sessID); }, 200, "OK", null); }