changeset 1319:f7355714742f

add Http.disable_luan()
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 04 Feb 2019 02:04:54 -0700
parents 35a6a195819f
children 2c8d1d76a82a
files src/luan/modules/http/LuanHandler.java
diffstat 1 files changed, 10 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/luan/modules/http/LuanHandler.java	Sun Feb 03 22:17:50 2019 -0700
+++ b/src/luan/modules/http/LuanHandler.java	Mon Feb 04 02:04:54 2019 -0700
@@ -37,13 +37,16 @@
 	private final ReadWriteLock lock = new ReentrantReadWriteLock();
 	private final List<Reference<Closeable>> onClose = new ArrayList<Reference<Closeable>>();
 	private volatile LuanState currentLuan;
+	private volatile boolean isDisabled = false;
 
 	private static final Method resetLuanMethod;
 	private static final Method evalInRootMethod;
+	private static final Method disableLuanMethod;
 	static {
 		try {
 			resetLuanMethod = LuanHandler.class.getMethod( "reset_luan" );
 			evalInRootMethod = LuanHandler.class.getMethod( "eval_in_root", String.class );
+			disableLuanMethod = LuanHandler.class.getMethod( "disable_luan" );
 		} catch(NoSuchMethodException e) {
 			throw new RuntimeException(e);
 		}
@@ -58,6 +61,7 @@
 			LuanTable Http = (LuanTable)luanInit.require("luan:http/Http.luan");
 			Http.put( "reset_luan", new LuanJavaFunction(resetLuanMethod,this) );
 			Http.put( "eval_in_root", new LuanJavaFunction(evalInRootMethod,this) );
+			Http.put( "disable_luan", new LuanJavaFunction(disableLuanMethod,this) );
 		} catch(LuanException e) {
 			throw new RuntimeException(e);
 		}
@@ -83,6 +87,8 @@
 	}
 */
 	@Override public Response handle(Request request) {
+		if( isDisabled )
+			return null;
 		if( request.path.endsWith("/") )
 			return null;
 		String modName = "site:" + request.path +".luan";
@@ -165,6 +171,10 @@
 		}.start();
 	}
 
+	public void disable_luan() {
+		isDisabled = true;
+	}
+
 	public Object runLuan(String sourceText,String sourceName) throws LuanException {
 		lock.readLock().lock();
 		try {