Mercurial Hosting > luan
comparison src/luan/modules/http/HttpServicer.java @ 1000:32d4b569567c
simplify handle()
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 19 Oct 2016 04:22:51 -0600 |
parents | 3dcc52e17535 |
children | 0d884377e923 |
comparison
equal
deleted
inserted
replaced
999:74b9daf2826c | 1000:32d4b569567c |
---|---|
16 import java.util.concurrent.Executors; | 16 import java.util.concurrent.Executors; |
17 import java.util.concurrent.atomic.AtomicInteger; | 17 import java.util.concurrent.atomic.AtomicInteger; |
18 import javax.servlet.ServletOutputStream; | 18 import javax.servlet.ServletOutputStream; |
19 import javax.servlet.ServletException; | 19 import javax.servlet.ServletException; |
20 import javax.servlet.http.Cookie; | 20 import javax.servlet.http.Cookie; |
21 import javax.servlet.http.HttpServletRequest; | 21 import org.eclipse.jetty.server.Request; |
22 import javax.servlet.http.HttpServletResponse; | 22 import javax.servlet.http.HttpServletResponse; |
23 import javax.servlet.http.Part; | 23 import javax.servlet.http.Part; |
24 import org.slf4j.Logger; | 24 import org.slf4j.Logger; |
25 import org.slf4j.LoggerFactory; | 25 import org.slf4j.LoggerFactory; |
26 import org.eclipse.jetty.util.MultiPartInputStream; | 26 import org.eclipse.jetty.util.MultiPartInputStream; |
47 @Override protected boolean removeEldestEntry(Map.Entry<String,LuanState> eldest) { | 47 @Override protected boolean removeEldestEntry(Map.Entry<String,LuanState> eldest) { |
48 return (Long)eldest.getValue().registry().get("sessionTimeout") < System.currentTimeMillis(); | 48 return (Long)eldest.getValue().registry().get("sessionTimeout") < System.currentTimeMillis(); |
49 } | 49 } |
50 }; | 50 }; |
51 | 51 |
52 public static boolean service(LuanState luan,HttpServletRequest request,HttpServletResponse response,String modName) | 52 public static boolean service(LuanState luan,Request request,HttpServletResponse response,String modName) |
53 throws LuanException | 53 throws LuanException |
54 { | 54 { |
55 LuanFunction fn; | 55 LuanFunction fn; |
56 synchronized(luan) { | 56 synchronized(luan) { |
57 PackageLuan.enableLoad(luan,"luan:http/Http.luan",modName); | 57 PackageLuan.enableLoad(luan,"luan:http/Http.luan",modName); |
263 | 263 |
264 private static String unescape(String value) { | 264 private static String unescape(String value) { |
265 return value.replaceAll("%3B", ";"); | 265 return value.replaceAll("%3B", ";"); |
266 } | 266 } |
267 | 267 |
268 private static Cookie getCookie(HttpServletRequest request,String name) { | 268 private static Cookie getCookie(Request request,String name) { |
269 Cookie[] cookies = request.getCookies(); | 269 Cookie[] cookies = request.getCookies(); |
270 if( cookies == null ) | 270 if( cookies == null ) |
271 return null; | 271 return null; |
272 for (Cookie cookie : cookies) { | 272 for (Cookie cookie : cookies) { |
273 if (cookie.getName().equals(name)) | 273 if (cookie.getName().equals(name)) |
274 return cookie; | 274 return cookie; |
275 } | 275 } |
276 return null; | 276 return null; |
277 } | 277 } |
278 | 278 |
279 public static void setCookie(HttpServletRequest request,HttpServletResponse response,String name,String value,boolean isPersistent, String domain) { | 279 public static void setCookie(Request request,HttpServletResponse response,String name,String value,boolean isPersistent, String domain) { |
280 Cookie cookie = getCookie(request,name); | 280 Cookie cookie = getCookie(request,name); |
281 if( cookie==null || !cookie.getValue().equals(value) ) { | 281 if( cookie==null || !cookie.getValue().equals(value) ) { |
282 cookie = new Cookie(name, escape(value)); | 282 cookie = new Cookie(name, escape(value)); |
283 cookie.setPath("/"); | 283 cookie.setPath("/"); |
284 if (domain != null && domain.length() > 0) | 284 if (domain != null && domain.length() > 0) |
287 cookie.setMaxAge(10000000); | 287 cookie.setMaxAge(10000000); |
288 response.addCookie(cookie); | 288 response.addCookie(cookie); |
289 } | 289 } |
290 } | 290 } |
291 | 291 |
292 public static void removeCookie(HttpServletRequest request, | 292 public static void removeCookie(Request request, |
293 HttpServletResponse response, | 293 HttpServletResponse response, |
294 String name, | 294 String name, |
295 String domain | 295 String domain |
296 ) { | 296 ) { |
297 Cookie cookie = getCookie(request, name); | 297 Cookie cookie = getCookie(request, name); |