comparison src/luan/modules/http/LuanHandler.java @ 1359:9721d4709bfb

minor
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 19 Apr 2019 00:58:18 -0600
parents 1d31c1f3ea30
children ee0f0e6c89a0
comparison
equal deleted inserted replaced
1358:1d31c1f3ea30 1359:9721d4709bfb
240 String modName = "site:" + request.path +".luan"; 240 String modName = "site:" + request.path +".luan";
241 LuanFunction fn; 241 LuanFunction fn;
242 Luan luan; 242 Luan luan;
243 synchronized(luanInit) { 243 synchronized(luanInit) {
244 enableLoad("luan:http/Http.luan",modName); 244 enableLoad("luan:http/Http.luan",modName);
245 PackageLuan.require(currentLuan,"luan:http/Http.luan"); 245 currentLuan.require("luan:http/Http.luan");
246 Object mod = PackageLuan.load(currentLuan,modName); 246 Object mod = PackageLuan.load(currentLuan,modName);
247 if( mod.equals(Boolean.FALSE) ) 247 if( mod.equals(Boolean.FALSE) )
248 return null; 248 return null;
249 if( !(mod instanceof LuanFunction) ) 249 if( !(mod instanceof LuanFunction) )
250 throw new LuanException( "module '"+modName+"' must return a function" ); 250 throw new LuanException( "module '"+modName+"' must return a function" );
260 } 260 }
261 261
262 private Response serviceNotFound(Request request) 262 private Response serviceNotFound(Request request)
263 throws LuanException 263 throws LuanException
264 { 264 {
265 LuanFunction fn;
265 Luan luan; 266 Luan luan;
266 synchronized(luanInit) { 267 synchronized(luanInit) {
267 enableLoad("luan:http/Http.luan"); 268 enableLoad("luan:http/Http.luan");
268 PackageLuan.require(currentLuan,"luan:http/Http.luan"); 269 LuanTable module = (LuanTable)currentLuan.require("luan:http/Http.luan");
270 fn = module.fn("not_found_handler");
271 if( fn == null )
272 return null;
269 LuanCloner cloner = new LuanCloner(LuanCloner.Type.INCREMENTAL); 273 LuanCloner cloner = new LuanCloner(LuanCloner.Type.INCREMENTAL);
270 luan = (Luan)cloner.clone(currentLuan); 274 luan = (Luan)cloner.clone(currentLuan);
275 fn = (LuanFunction)cloner.get(fn);
271 } 276 }
272 LuanTable module = (LuanTable)luan.require("luan:http/Http.luan"); 277 LuanTable module = (LuanTable)luan.require("luan:http/Http.luan");
273 LuanFunction fn = module.fn("not_found_handler");
274 if( fn == null )
275 return null;
276 module.fn("new_request").call(request); 278 module.fn("new_request").call(request);
277 module.fn("new_response").call(); 279 module.fn("new_response").call();
278 Object obj = Luan.first(fn.call()); 280 Object obj = Luan.first(fn.call());
279 if( !(obj instanceof Boolean) ) 281 if( !(obj instanceof Boolean) )
280 throw new LuanException("not_found_handler must return boolean"); 282 throw new LuanException("not_found_handler must return boolean");