diff src/luan/modules/http/LuanHandler.java @ 1256:c147e2e877e3

allow subclassing of HttpServicer
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 19 Sep 2018 20:15:16 -0600
parents 0b75337bb91a
children e38f5869e9df
line wrap: on
line diff
--- a/src/luan/modules/http/LuanHandler.java	Mon Sep 03 06:13:55 2018 -0600
+++ b/src/luan/modules/http/LuanHandler.java	Wed Sep 19 20:15:16 2018 -0600
@@ -14,7 +14,6 @@
 import luan.webserver.Response;
 import luan.webserver.Server;
 import luan.webserver.Handler;
-import luan.webserver.Status;
 import luan.webserver.ResponseOutputStream;
 import luan.Luan;
 import luan.LuanState;
@@ -29,6 +28,7 @@
 public class LuanHandler implements Handler, Closeable {
 	private final LuanState luanInit;
 	private final Logger logger;
+	private final HttpServicer httpServicer;
 	private final ReadWriteLock lock = new ReentrantReadWriteLock();
 	private LuanState luan;
 
@@ -41,7 +41,7 @@
 		}
 	}
 
-	public LuanHandler(LuanState luanInit,String loggerRoot) {
+	public LuanHandler(LuanState luanInit,String loggerRoot,HttpServicer httpServicer) {
 		this.luanInit = luanInit;
 		if( loggerRoot==null )
 			loggerRoot = "";
@@ -52,6 +52,7 @@
 		} catch(LuanException e) {
 			throw new RuntimeException(e);
 		}
+		this.httpServicer = httpServicer!=null ? httpServicer : new HttpServicer();
 		setLuan();
 		luanInit.onClose(this);
 	}
@@ -80,14 +81,7 @@
 		thread.setName(request.headers.get("host")+request.path);
 		lock.readLock().lock();
 		try {
-			Response response = HttpServicer.service(luan,request,modName);
-			return response;
-		} catch(LuanException e) {
-//e.printStackTrace();
-			String err = e.getLuanStackTraceString();
-			logger.error(err+"\n"+request.rawHead.trim()+"\n");
-			String msg = "Internel Server Error\n\n" + err;
-			return Response.errorResponse( Status.INTERNAL_SERVER_ERROR, msg );
+			return httpServicer.service(luan,request,modName);
 		} finally {
 			lock.readLock().unlock();
 			thread.setName(oldName);