Mercurial Hosting > luan
comparison 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 |
comparison
equal
deleted
inserted
replaced
1152:21d157b153fe | 1153:1f4da56abd4f |
---|---|
154 } catch(ServletException e) { | 154 } catch(ServletException e) { |
155 throw new RuntimeException(e); | 155 throw new RuntimeException(e); |
156 } | 156 } |
157 } | 157 } |
158 | 158 |
159 LuanTable cookieTbl = (LuanTable)requestTbl.rawGet("cookie"); | 159 LuanTable cookieTbl = (LuanTable)requestTbl.rawGet("cookies"); |
160 for( Cookie cookie : request.getCookies() ) { | 160 for( Cookie cookie : request.getCookies() ) { |
161 cookieTbl.rawPut( cookie.getName(), unescape(cookie.getValue()) ); | 161 cookieTbl.rawPut( cookie.getName(), unescape(cookie.getValue()) ); |
162 } | 162 } |
163 | 163 |
164 | 164 |
226 return cookie; | 226 return cookie; |
227 } | 227 } |
228 return null; | 228 return null; |
229 } | 229 } |
230 | 230 |
231 public static void setCookie(HttpServletRequest request,HttpServletResponse response,String name,String value,boolean isPersistent, String domain) { | 231 public static void setCookie(HttpServletRequest request,HttpServletResponse response,String name,String value,LuanTable attributes) { |
232 Cookie cookie = getCookie(request,name); | 232 Cookie cookie = getCookie(request,name); |
233 if( cookie==null || !cookie.getValue().equals(value) ) { | 233 if( cookie==null || !cookie.getValue().equals(value) ) { |
234 cookie = new Cookie(name, escape(value)); | 234 cookie = new Cookie(name, escape(value)); |
235 cookie.setPath("/"); | 235 if( attributes != null ) { |
236 if (domain != null && domain.length() > 0) | 236 String path = (String)attributes.rawGet("Path"); |
237 cookie.setDomain(domain); | 237 if( path != null ) |
238 if( isPersistent ) | 238 cookie.setPath(path); |
239 cookie.setMaxAge(10000000); | 239 String domain = (String)attributes.rawGet("Domain"); |
240 if (domain != null && domain.length() > 0) | |
241 cookie.setDomain(domain); | |
242 String maxAge = (String)attributes.rawGet("Max-Age"); | |
243 if( maxAge != null ) | |
244 cookie.setMaxAge(Integer.parseInt(maxAge)); | |
245 } | |
240 response.addCookie(cookie); | 246 response.addCookie(cookie); |
241 } | |
242 } | |
243 | |
244 public static void removeCookie(HttpServletRequest request, | |
245 HttpServletResponse response, | |
246 String name, | |
247 String domain | |
248 ) { | |
249 Cookie cookie = getCookie(request, name); | |
250 if(cookie != null) { | |
251 Cookie delCookie = new Cookie(name, "delete"); | |
252 delCookie.setPath("/"); | |
253 delCookie.setMaxAge(0); | |
254 if (domain != null && domain.length() > 0) | |
255 delCookie.setDomain(domain); | |
256 response.addCookie(delCookie); | |
257 } | 247 } |
258 } | 248 } |
259 | 249 |
260 | 250 |
261 | 251 |