Mercurial Hosting > luan
comparison src/luan/modules/http/HttpServicer.java @ 1265:3f4644246e39
LuanHandler cleanup and add Server.serve_for_proxy
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 25 Sep 2018 19:51:34 -0600 |
parents | 382c444a6c77 |
children | 9fa8b8389578 |
comparison
equal
deleted
inserted
replaced
1264:d41997776788 | 1265:3f4644246e39 |
---|---|
2 | 2 |
3 import org.slf4j.Logger; | 3 import org.slf4j.Logger; |
4 import org.slf4j.LoggerFactory; | 4 import org.slf4j.LoggerFactory; |
5 import luan.webserver.Request; | 5 import luan.webserver.Request; |
6 import luan.webserver.Response; | 6 import luan.webserver.Response; |
7 import luan.webserver.Status; | |
8 import luan.LuanState; | 7 import luan.LuanState; |
9 import luan.LuanFunction; | 8 import luan.LuanFunction; |
10 import luan.LuanException; | 9 import luan.LuanException; |
11 import luan.LuanTable; | 10 import luan.LuanTable; |
12 import luan.LuanCloner; | 11 import luan.LuanCloner; |
14 | 13 |
15 | 14 |
16 public final class HttpServicer { | 15 public final class HttpServicer { |
17 private static final Logger logger = LoggerFactory.getLogger(HttpServicer.class); | 16 private static final Logger logger = LoggerFactory.getLogger(HttpServicer.class); |
18 | 17 |
19 public static Response service(LuanState luan,Request request,String modName) { | 18 public static Response service(LuanState luan,Request request,String modName) |
19 throws LuanException | |
20 { | |
20 try { | 21 try { |
21 return serviceLuan(luan,request,modName); | 22 return serviceLuan(luan,request,modName); |
22 } catch(LuanException e) { | 23 } catch(LuanException e) { |
23 return handleError(luan,request,e); | 24 return handleError(luan,request,e); |
24 } | 25 } |
25 } | 26 } |
26 | 27 |
27 private static Response handleError(LuanState luan,Request request,LuanException e) { | 28 private static Response handleError(LuanState luan,Request request,LuanException e) |
29 throws LuanException | |
30 { | |
28 //e.printStackTrace(); | 31 //e.printStackTrace(); |
29 /* | |
30 String err = e.getLuanStackTraceString(); | |
31 logger.error(err+"\n"+request.rawHead.trim()+"\n"); | |
32 String msg = "Internel Server Error\n\n" + err; | |
33 return Response.errorResponse( Status.INTERNAL_SERVER_ERROR, msg ); | |
34 */ | |
35 synchronized(luan) { | 32 synchronized(luan) { |
36 LuanCloner cloner = new LuanCloner(LuanCloner.Type.INCREMENTAL); | 33 LuanCloner cloner = new LuanCloner(LuanCloner.Type.INCREMENTAL); |
37 luan = (LuanState)cloner.clone(luan); | 34 luan = (LuanState)cloner.clone(luan); |
38 } | 35 } |
39 try { | 36 LuanTable module = (LuanTable)PackageLuan.require(luan,"luan:http/Http.luan"); |
40 LuanTable module = (LuanTable)PackageLuan.require(luan,"luan:http/Http.luan"); | 37 LuanFunction fn = (LuanFunction)module.rawGet("handle_error"); |
41 LuanFunction fn = (LuanFunction)module.rawGet("handle_error"); | 38 return (Response)fn.call( luan, new Object[]{request,e.table()} ); |
42 return (Response)fn.call( luan, new Object[]{request,e.table()} ); | |
43 } catch(LuanException e2) { | |
44 throw new RuntimeException(e2); | |
45 } | |
46 } | 39 } |
47 | 40 |
48 private static Response serviceLuan(LuanState luan,Request request,String modName) | 41 private static Response serviceLuan(LuanState luan,Request request,String modName) |
49 throws LuanException | 42 throws LuanException |
50 { | 43 { |