view src/luan/modules/http/LuanDomainHandler.java @ 1336:7483108154bb

minor logging
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 14 Feb 2019 05:22:22 -0700
parents 25746915a241
children 643cf1c37723
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.Luan;
import luan.LuanTable;
import luan.LuanCloner;
import luan.LuanException;
import luan.modules.logging.Log4j;


public class LuanDomainHandler implements Handler, DomainHandler.Factory {

	private final Luan luanInit;
	private final DomainHandler domainHandler = new DomainHandler(this);

	public LuanDomainHandler(Luan luanInit) {
		LuanCloner cloner = new LuanCloner(LuanCloner.Type.COMPLETE);
		this.luanInit = (Luan)cloner.clone(luanInit);
	}

	@Override public Handler newHandler(String domain) {
		Luan luan = newLuan(domain);
		return new LuanHandler(luan);
	}

	protected void newLoggerRepository(Luan luan) {
		Log4j.newLoggerRepository(luan);
	}

	protected Luan newLuan(String domain) {
		LuanCloner cloner = new LuanCloner(LuanCloner.Type.COMPLETE);
		Luan luan = (Luan)cloner.clone(luanInit);
		newLoggerRepository(luan);
		try {
			LuanTable Http = (LuanTable)luan.require("luan:http/Http.luan");
			Http.put( "domain", domain );
		} catch(LuanException e) {
			throw new RuntimeException(e);
		}
		return luan;
	}

	@Override public Response handle(Request request) {
		return domainHandler.handle(request);
	}
}