changeset 1839:908a43d14206

add Http.link_to_domain
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 30 Jan 2025 18:14:15 -0700
parents ffca75e80799
children d0398bade693
files src/luan/modules/http/LuanDomainHandler.java src/luan/modules/http/LuanHandler.java
diffstat 2 files changed, 21 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/luan/modules/http/LuanDomainHandler.java	Fri Jan 17 22:46:35 2025 -0700
+++ b/src/luan/modules/http/LuanDomainHandler.java	Thu Jan 30 18:14:15 2025 -0700
@@ -24,7 +24,11 @@
 
 	@Override public Handler newHandler(String domain) {
 		Luan luan = newLuan(domain);
-		return new LuanHandler(luan,domain);
+		LuanHandler handler = new LuanHandler(luan,domain);
+		String luanDomain = handler.getDomain();
+		if( !luanDomain.equals(domain) )
+			return domainHandler.getHandler(luanDomain);
+		return handler;
 	}
 
 	protected Luan newLuan(final String domain) {
--- a/src/luan/modules/http/LuanHandler.java	Fri Jan 17 22:46:35 2025 -0700
+++ b/src/luan/modules/http/LuanHandler.java	Thu Jan 30 18:14:15 2025 -0700
@@ -35,7 +35,7 @@
 	private static final Logger logger = LoggerFactory.getLogger(LuanHandler.class);
 
 	private final Luan luanInit;
-	public final String domain;
+	private String domain;
 	private final ReadWriteLock rwLock = new ReentrantReadWriteLock();
 	private volatile Luan currentLuan;
 	private volatile boolean isDisabled = false;
@@ -46,12 +46,14 @@
 	private static final Method evalInRootMethod;
 	private static final Method disableLuanMethod;
 	private static final Method testAsInitMethod;
+	private static final Method linkToDomainMethod;
 	static {
 		try {
 			resetLuanMethod = LuanHandler.Fns.class.getMethod( "reset_luan" );
 			evalInRootMethod = LuanHandler.Fns.class.getMethod( "eval_in_root", String.class );
 			disableLuanMethod = LuanHandler.Fns.class.getMethod( "disable_luan" );
 			testAsInitMethod = LuanHandler.Fns.class.getMethod( "test_as_init", String.class, String.class );
+			linkToDomainMethod = LuanHandler.Fns.class.getMethod( "link_to_domain", String.class );
 		} catch(NoSuchMethodException e) {
 			throw new RuntimeException(e);
 		}
@@ -68,6 +70,7 @@
 			Http.put( luanInit, "eval_in_root", new LuanJavaFunction(evalInRootMethod,fns) );
 			Http.put( luanInit, "disable_luan", new LuanJavaFunction(disableLuanMethod,fns) );
 			Http.put( luanInit, "test_as_init", new LuanJavaFunction(testAsInitMethod,fns) );
+			Http.put( luanInit, "link_to_domain", new LuanJavaFunction(linkToDomainMethod,fns) );
 		} catch(LuanException e) {
 			throw new RuntimeException(e);
 		}
@@ -84,6 +87,10 @@
 			logger.warn("gc "+domain);
 	}
 
+	public String getDomain() {
+		return domain;
+	}
+
 	private void init(Luan luan) throws LuanException {
 		if( didInit )
 			return;
@@ -220,6 +227,10 @@
 		}
 	}
 
+	private void link_to_domain(String domain) throws LuanException {
+		this.domain = domain;
+	}
+
 	public static final class Fns implements ThreadLuan.Closeables {
 		private final Reference<LuanHandler> ref;
 
@@ -256,6 +267,10 @@
 		public void test_as_init(String text,String sourceName) throws LuanException {
 			lh().test_as_init(text,sourceName);
 		}
+
+		public void link_to_domain(String domain) throws LuanException {
+			lh().link_to_domain(domain);
+		}
 	}