Mercurial Hosting > luan
annotate src/luan/modules/http/LuanDomainHandler.java @ 1328:55b8210b4ec0
add MDC host
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sat, 09 Feb 2019 21:49:42 -0700 |
parents | 307e76ccd0d6 |
children | 5a39b006acd1 |
rev | line source |
---|---|
1315 | 1 package luan.modules.http; |
2 | |
1328 | 3 import org.apache.log4j.MDC; |
1315 | 4 import luan.webserver.Request; |
5 import luan.webserver.Response; | |
6 import luan.webserver.Handler; | |
7 import luan.webserver.handlers.DomainHandler; | |
8 import luan.LuanState; | |
9 import luan.LuanTable; | |
10 import luan.LuanCloner; | |
11 import luan.LuanException; | |
1321
307e76ccd0d6
generalize separate logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1315
diff
changeset
|
12 import luan.modules.logging.LuanLogger; |
1315 | 13 |
14 | |
15 public final class LuanDomainHandler implements Handler { | |
16 | |
17 private final LuanState luanInit; | |
18 | |
19 private final DomainHandler.Factory factory = new DomainHandler.Factory() { | |
20 public Handler newHandler(String domain) { | |
21 LuanCloner cloner = new LuanCloner(LuanCloner.Type.COMPLETE); | |
22 LuanState luan = (LuanState)cloner.clone(luanInit); | |
23 try { | |
1321
307e76ccd0d6
generalize separate logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1315
diff
changeset
|
24 LuanLogger.newLoggerRepository(luan); |
1315 | 25 LuanTable Http = (LuanTable)luan.require("luan:http/Http.luan"); |
26 Http.put( "domain", domain ); | |
27 } catch(LuanException e) { | |
28 throw new RuntimeException(e); | |
29 } | |
1321
307e76ccd0d6
generalize separate logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1315
diff
changeset
|
30 return new LuanHandler(luan); |
1315 | 31 } |
32 }; | |
33 | |
34 private final DomainHandler domainHandler = new DomainHandler(factory); | |
35 | |
36 public LuanDomainHandler(LuanState luanInit) { | |
37 LuanCloner cloner = new LuanCloner(LuanCloner.Type.COMPLETE); | |
38 this.luanInit = (LuanState)cloner.clone(luanInit); | |
39 } | |
40 | |
41 @Override public Response handle(Request request) { | |
1328 | 42 String host = (String)request.headers.get("host"); |
43 MDC.put("host",host); | |
44 try { | |
45 return domainHandler.handle(request); | |
46 } finally { | |
47 MDC.remove("host"); | |
48 } | |
1315 | 49 } |
50 } |