Mercurial Hosting > luan
diff src/luan/modules/http/impl/HttpServicer.java @ 1163:fef8f0742da9
minor
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 06 Feb 2018 22:04:47 -0700 |
parents | 4beabb087be6 |
children | 7e6f28c769a1 |
line wrap: on
line diff
--- a/src/luan/modules/http/impl/HttpServicer.java Tue Feb 06 21:25:55 2018 -0700 +++ b/src/luan/modules/http/impl/HttpServicer.java Tue Feb 06 22:04:47 2018 -0700 @@ -1,15 +1,9 @@ package luan.modules.http.impl; -import java.io.Closeable; -import java.io.IOException; -import java.util.Map; -import java.util.HashMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import luan.webserver.Request; import luan.webserver.Response; -import luan.webserver.Status; -import luan.Luan; import luan.LuanState; import luan.LuanFunction; import luan.LuanException; @@ -48,51 +42,14 @@ newRequestFn.call( luan, new Object[]{request} ); // response - Response response = new Response(); LuanFunction newResponseFn = (LuanFunction)module.rawGet("new_response"); - LuanTable responseTbl = (LuanTable)newResponseFn.call( luan, new Object[]{response} ); + newResponseFn.call(luan); fn.call(luan); - response.status = Status.getStatus( Luan.asInteger(responseTbl.rawGet("status")) ); - LuanTable headersTbl = (LuanTable)responseTbl.rawGet("headers"); - if( !headersTbl.rawIsEmpty() ) { - Map headers = (Map)Luan.toJava(headersTbl); - for( Object obj : headers.entrySet() ) { - Map.Entry entry = (Map.Entry)obj; - String name = (String)entry.getKey(); - Object value = entry.getValue(); - response.headers.put(name,value); - } - } - Closeable writer = (Closeable)responseTbl.rawGet("writer"); - if( writer != null ) { - try { - ((Closeable)writer).close(); - } catch(IOException e) { - throw new RuntimeException(e); - } - } - + LuanFunction finishFn = (LuanFunction)module.rawGet("finish"); + Response response = (Response)finishFn.call(luan); return response; } - public static void setCookie(LuanState luan,Response response,String name,String value,LuanTable attributesTbl) - throws LuanException - { - Map<String,String> attributes = new HashMap<String,String>(); - if( attributesTbl != null ) { - for( Map.Entry entry : attributesTbl.iterable(luan) ) { - String key = (String)entry.getKey(); - if( !(key instanceof String) ) - throw new LuanException("cookie attribute name must be string"); - String val = (String)entry.getValue(); - if( !(val instanceof String) ) - throw new LuanException("cookie attribute value must be string"); - attributes.put(key,val); - } - } - response.setCookie(name,value,attributes); - } - }