Mercurial Hosting > luan
view 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 |
line wrap: on
line source
package luan.modules.http; import luan.webserver.Request; import luan.webserver.Response; import luan.webserver.Handler; import luan.webserver.handlers.DomainHandler; import luan.LuanState; import luan.LuanTable; import luan.LuanCloner; import luan.LuanException; public final class LuanDomainHandler implements Handler { private final LuanState luanInit; private final DomainHandler.Factory factory = new DomainHandler.Factory() { public Handler newHandler(String domain) { LuanCloner cloner = new LuanCloner(LuanCloner.Type.COMPLETE); LuanState luan = (LuanState)cloner.clone(luanInit); try { LuanTable Http = (LuanTable)luan.require("luan:http/Http.luan"); Http.put( "domain", domain ); } catch(LuanException e) { throw new RuntimeException(e); } return new LuanHandler(luan,null); } }; private final DomainHandler domainHandler = new DomainHandler(factory); public LuanDomainHandler(LuanState luanInit) { LuanCloner cloner = new LuanCloner(LuanCloner.Type.COMPLETE); this.luanInit = (LuanState)cloner.clone(luanInit); } @Override public Response handle(Request request) { return domainHandler.handle(request); } }