comparison src/luan/modules/http/LuanHandler.java @ 1618:a37ffe2d1b14

fix not_found_handler
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 14 Jun 2021 18:45:17 -0600
parents 38894708bade
children 8d751af51b9d
comparison
equal deleted inserted replaced
1617:d88fb2eb15aa 1618:a37ffe2d1b14
257 Luan luan; 257 Luan luan;
258 synchronized(currentLuan) { 258 synchronized(currentLuan) {
259 luan = new Luan(currentLuan); 259 luan = new Luan(currentLuan);
260 } 260 }
261 LuanTable module = (LuanTable)luan.require("luan:http/Http.luan"); 261 LuanTable module = (LuanTable)luan.require("luan:http/Http.luan");
262 return (Response)module.fn("handle_error").call( luan, request, e.table(luan) ); 262 return (Response)module.fn(luan,"handle_error").call( luan, request, e.table(luan) );
263 } 263 }
264 264
265 private Response serviceLuan(Request request) 265 private Response serviceLuan(Request request)
266 throws LuanException 266 throws LuanException
267 { 267 {
277 throw new LuanException( "module '"+modName+"' must return a function" ); 277 throw new LuanException( "module '"+modName+"' must return a function" );
278 luan = new Luan(currentLuan); 278 luan = new Luan(currentLuan);
279 fn = (LuanFunction)mod; 279 fn = (LuanFunction)mod;
280 } 280 }
281 LuanTable module = (LuanTable)luan.require("luan:http/Http.luan"); 281 LuanTable module = (LuanTable)luan.require("luan:http/Http.luan");
282 module.fn("new_request").call(luan,request); 282 module.fn(luan,"new_request").call(luan,request);
283 module.fn("new_response").call(luan); 283 module.fn(luan,"new_response").call(luan);
284 fn.call(luan); 284 fn.call(luan);
285 return (Response)module.fn("finish").call(luan); 285 return (Response)module.fn(luan,"finish").call(luan);
286 } 286 }
287 287
288 private Response serviceNotFound(Request request) 288 private Response serviceNotFound(Request request)
289 throws LuanException 289 throws LuanException
290 { 290 {
291 LuanFunction fn; 291 LuanFunction fn;
292 Luan luan; 292 Luan luan;
293 synchronized(currentLuan) { 293 synchronized(currentLuan) {
294 LuanTable module = (LuanTable)currentLuan.require("luan:http/Http.luan"); 294 LuanTable module = (LuanTable)currentLuan.require("luan:http/Http.luan");
295 fn = module.fn("not_found_handler"); 295 fn = module.fn(currentLuan,"not_found_handler");
296 if( fn == null ) 296 if( fn == null )
297 return null; 297 return null;
298 luan = new Luan(currentLuan); 298 luan = new Luan(currentLuan);
299 } 299 }
300 LuanTable module = (LuanTable)luan.require("luan:http/Http.luan"); 300 LuanTable module = (LuanTable)luan.require("luan:http/Http.luan");
301 module.fn("new_request").call(luan,request); 301 module.fn(luan,"new_request").call(luan,request);
302 module.fn("new_response").call(luan); 302 module.fn(luan,"new_response").call(luan);
303 Object obj = Luan.first(fn.call(luan)); 303 Object obj = Luan.first(fn.call(luan));
304 if( !(obj instanceof Boolean) ) 304 if( !(obj instanceof Boolean) )
305 throw new LuanException("not_found_handler must return boolean"); 305 throw new LuanException("not_found_handler must return boolean");
306 boolean handled = (Boolean)obj; 306 boolean handled = (Boolean)obj;
307 return handled ? (Response)module.fn("finish").call(luan) : null; 307 return handled ? (Response)module.fn(luan,"finish").call(luan) : null;
308 } 308 }
309 309
310 } 310 }