Mercurial Hosting > luan
diff src/luan/modules/http/jetty/HttpServicer.java @ 1152:21d157b153fe
change http parameters interface
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 04 Feb 2018 19:25:12 -0700 |
parents | 0842b9b570f8 |
children | 1f4da56abd4f |
line wrap: on
line diff
--- a/src/luan/modules/http/jetty/HttpServicer.java Sun Feb 04 18:50:25 2018 -0700 +++ b/src/luan/modules/http/jetty/HttpServicer.java Sun Feb 04 19:25:12 2018 -0700 @@ -28,7 +28,6 @@ import luan.LuanFunction; import luan.LuanException; import luan.LuanTable; -//import luan.LuanPropertyMeta; import luan.LuanCloner; import luan.modules.PackageLuan; import luan.modules.IoLuan; @@ -102,7 +101,9 @@ String contentType = request.getContentType(); if( contentType==null || !contentType.startsWith("multipart/form-data") ) { for( Map.Entry<String,String[]> entry : request.getParameterMap().entrySet() ) { - parametersTbl.rawPut(entry.getKey(),new LuanTable(Arrays.asList(entry.getValue()))); + String[] a = entry.getValue(); + Object value = a.length==1 ? a[0] : new LuanTable(Arrays.asList(a)); + parametersTbl.rawPut(entry.getKey(),value); } } else { // multipart try { @@ -124,52 +125,29 @@ if( filename == null ) { value = new String(part.getBytes()); } else { -/* - LuanTable partTbl = LuanPropertyMeta.INSTANCE.newTable(); - partTbl.rawPut("filename",filename); - partTbl.rawPut("content_type",part.getContentType()); - LuanPropertyMeta.INSTANCE.getters(partTbl).rawPut( "content", new LuanFunction() { - @Override public Object call(LuanState luan,Object[] args) throws LuanException { - try { - InputStream in = part.getInputStream(); - byte[] content = Utils.readAll(in); - in.close(); - return content; - } catch(IOException e) { - throw new RuntimeException(e); - } - } - } ); -*/ LuanTable partTbl = new LuanTable(); partTbl.rawPut("filename",filename); partTbl.rawPut("content_type",part.getContentType()); - LuanTable mt = new LuanTable(); - partTbl.setMetatable(mt); - mt.rawPut( "__index", new LuanFunction() { - @Override public Object call(LuanState luan,Object[] args) throws LuanException { - Object key = args[1]; - if( "content".equals(key) ) { - try { - InputStream in = part.getInputStream(); - byte[] content = Utils.readAll(in); - in.close(); - return content; - } catch(IOException e) { - throw new RuntimeException(e); - } - } - return null; - } - } ); + { + InputStream inPart = part.getInputStream(); + byte[] content = Utils.readAll(inPart); + inPart.close(); + partTbl.rawPut("content",content); + } value = partTbl; } - LuanTable list = (LuanTable)parametersTbl.rawGet(name); - if( list == null ) { - list = new LuanTable(); + Object obj = parametersTbl.rawGet(name); + if( obj == null ) { + parametersTbl.rawPut(name,value); + } else if( obj instanceof LuanTable && ((LuanTable)obj).isList() ) { + LuanTable list = (LuanTable)obj; + list.rawPut(list.rawLength()+1,value); + } else { + LuanTable list = new LuanTable(); + list.rawPut(1,obj); + list.rawPut(2,value); parametersTbl.rawPut(name,list); } - list.rawPut(parametersTbl.rawLength()+1,value); } } catch(IOException e) { throw new RuntimeException(e);