Mercurial Hosting > luan
comparison src/luan/modules/http/LuanDomainHandler.java @ 1315:5763597ca5c0
add DomainHandler
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 30 Jan 2019 01:21:49 -0700 |
parents | |
children | 307e76ccd0d6 |
comparison
equal
deleted
inserted
replaced
1314:51a1987b55a3 | 1315:5763597ca5c0 |
---|---|
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 } |