Handling cookies
Vert.x-Web使用CookieHandler来支持cookies.
你必须确保当请求需要cookies支持的时候,你已经设置上了cookie handler。
router.route().handler(CookieHandler.create());
Manipulating cookies
你可以向getCookie()方法, 或者通过cookies()方法检索出cookie集合.
getCookie(), 传递一个cookie name的参数来检索出一个cookiecookies(), 检索出cookie集合removeCookie, 删除一个cookieaddCookie, 添加一个cookie
当response headers被写回的时候, cookies集合会自动的被写入到response中.
Cookies是通过Cookie实例进行描述的. 你可以通过该实例检索出cookie中的name, value, domain, path 或者其他的cookie属性.
下面的例子演示了如何检索和添加cookie
router.route().handler(CookieHandler.create());router.route("some/path/").handler(routingContext -> {Cookie someCookie = routingContext.getCookie("mycookie");String cookieValue = someCookie.getValue();// Do something with cookie...// Add a cookie - this will get written back in the response automaticallyroutingContext.addCookie(Cookie.cookie("othercookie", "somevalue"));});
