1315
|
1 package luan.modules.http;
|
|
2
|
|
3 import luan.webserver.Request;
|
|
4 import luan.webserver.Response;
|
|
5 import luan.webserver.Handler;
|
|
6 import luan.webserver.handlers.DomainHandler;
|
|
7 import luan.LuanState;
|
|
8 import luan.LuanTable;
|
|
9 import luan.LuanCloner;
|
|
10 import luan.LuanException;
|
|
11
|
|
12
|
|
13 public final class LuanDomainHandler implements Handler {
|
|
14
|
|
15 private final LuanState luanInit;
|
|
16
|
|
17 private final DomainHandler.Factory factory = new DomainHandler.Factory() {
|
|
18 public Handler newHandler(String domain) {
|
|
19 LuanCloner cloner = new LuanCloner(LuanCloner.Type.COMPLETE);
|
|
20 LuanState luan = (LuanState)cloner.clone(luanInit);
|
|
21 try {
|
|
22 LuanTable Http = (LuanTable)luan.require("luan:http/Http.luan");
|
|
23 Http.put( "domain", domain );
|
|
24 } catch(LuanException e) {
|
|
25 throw new RuntimeException(e);
|
|
26 }
|
|
27 return new LuanHandler(luan,null);
|
|
28 }
|
|
29 };
|
|
30
|
|
31 private final DomainHandler domainHandler = new DomainHandler(factory);
|
|
32
|
|
33 public LuanDomainHandler(LuanState luanInit) {
|
|
34 LuanCloner cloner = new LuanCloner(LuanCloner.Type.COMPLETE);
|
|
35 this.luanInit = (LuanState)cloner.clone(luanInit);
|
|
36 }
|
|
37
|
|
38 @Override public Response handle(Request request) {
|
|
39 return domainHandler.handle(request);
|
|
40 }
|
|
41 }
|