Mercurial Hosting > luan
diff src/luan/modules/http/jetty/HttpServicer.java @ 1153:1f4da56abd4f
change http cookies interface
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 04 Feb 2018 20:01:23 -0700 |
parents | 21d157b153fe |
children | bbad9a21277c |
line wrap: on
line diff
--- a/src/luan/modules/http/jetty/HttpServicer.java Sun Feb 04 19:25:12 2018 -0700 +++ b/src/luan/modules/http/jetty/HttpServicer.java Sun Feb 04 20:01:23 2018 -0700 @@ -156,7 +156,7 @@ } } - LuanTable cookieTbl = (LuanTable)requestTbl.rawGet("cookie"); + LuanTable cookieTbl = (LuanTable)requestTbl.rawGet("cookies"); for( Cookie cookie : request.getCookies() ) { cookieTbl.rawPut( cookie.getName(), unescape(cookie.getValue()) ); } @@ -228,35 +228,25 @@ return null; } - public static void setCookie(HttpServletRequest request,HttpServletResponse response,String name,String value,boolean isPersistent, String domain) { + public static void setCookie(HttpServletRequest request,HttpServletResponse response,String name,String value,LuanTable attributes) { Cookie cookie = getCookie(request,name); if( cookie==null || !cookie.getValue().equals(value) ) { cookie = new Cookie(name, escape(value)); - cookie.setPath("/"); - if (domain != null && domain.length() > 0) - cookie.setDomain(domain); - if( isPersistent ) - cookie.setMaxAge(10000000); + if( attributes != null ) { + String path = (String)attributes.rawGet("Path"); + if( path != null ) + cookie.setPath(path); + String domain = (String)attributes.rawGet("Domain"); + if (domain != null && domain.length() > 0) + cookie.setDomain(domain); + String maxAge = (String)attributes.rawGet("Max-Age"); + if( maxAge != null ) + cookie.setMaxAge(Integer.parseInt(maxAge)); + } response.addCookie(cookie); } } - public static void removeCookie(HttpServletRequest request, - HttpServletResponse response, - String name, - String domain - ) { - Cookie cookie = getCookie(request, name); - if(cookie != null) { - Cookie delCookie = new Cookie(name, "delete"); - delCookie.setPath("/"); - delCookie.setMaxAge(0); - if (domain != null && domain.length() > 0) - delCookie.setDomain(domain); - response.addCookie(delCookie); - } - } - private static String RUN_LATER_KEY = "Http.run_later";