comparison src/luan/modules/http/HttpServicer.java @ 1171:794ddcfbee20

remove http/impl
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 11 Feb 2018 02:41:23 -0700
parents src/luan/modules/http/impl/HttpServicer.java@7e6f28c769a1
children 354e661dee7f
comparison
equal deleted inserted replaced
1170:3a0f58d09ee7 1171:794ddcfbee20
1 package luan.modules.http;
2
3 import org.slf4j.Logger;
4 import org.slf4j.LoggerFactory;
5 import luan.webserver.Request;
6 import luan.webserver.Response;
7 import luan.LuanState;
8 import luan.LuanFunction;
9 import luan.LuanException;
10 import luan.LuanTable;
11 import luan.LuanCloner;
12 import luan.modules.PackageLuan;
13
14
15 public final class HttpServicer {
16 private static final Logger logger = LoggerFactory.getLogger(HttpServicer.class);
17
18 public static Response service(LuanState luan,Request request,String modName)
19 throws LuanException
20 {
21 LuanFunction fn;
22 synchronized(luan) {
23 PackageLuan.enableLoad(luan,"luan:http/Http.luan",modName);
24 LuanTable module = (LuanTable)PackageLuan.require(luan,"luan:http/Http.luan");
25 Object mod = PackageLuan.load(luan,modName);
26 if( mod.equals(Boolean.FALSE) )
27 return null;
28 if( !(mod instanceof LuanFunction) )
29 throw new LuanException( "module '"+modName+"' must return a function" );
30 LuanCloner cloner = new LuanCloner(LuanCloner.Type.INCREMENTAL);
31 luan = (LuanState)cloner.clone(luan);
32 fn = (LuanFunction)cloner.get(mod);
33 }
34
35 LuanTable module = (LuanTable)PackageLuan.require(luan,"luan:http/Http.luan");
36
37 // request
38 LuanFunction newRequestFn = (LuanFunction)module.rawGet("new_request");
39 newRequestFn.call( luan, new Object[]{request} );
40
41 // response
42 LuanFunction newResponseFn = (LuanFunction)module.rawGet("new_response");
43 newResponseFn.call(luan);
44
45 fn.call(luan);
46
47 LuanFunction finishFn = (LuanFunction)module.rawGet("finish");
48 Response response = (Response)finishFn.call(luan);
49 return response;
50 }
51
52 }