changeset 362:9dbf3433f70f

remove Http.request.get_parameter_values and Http.request.parts; multiple parameter values are now directly returned from indexing Http.request.parameters; multipart values are now in parameters;
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 15 Apr 2015 20:33:47 -0600
parents 0581238084ad
children 17b02b56d806
files web/src/luan/modules/web/HttpServicer.java
diffstat 1 files changed, 17 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/web/src/luan/modules/web/HttpServicer.java	Wed Apr 15 16:58:51 2015 -0600
+++ b/web/src/luan/modules/web/HttpServicer.java	Wed Apr 15 20:33:47 2015 -0600
@@ -123,7 +123,8 @@
 		LuanTable parameters = new NameTable() {
 
 			@Override Object get(String name) {
-				return request.getParameter(name);
+				String[] a = request.getParameterValues(name);
+				return a==null ? null : a.length==1 ? a[0] : a;
 			}
 
 			@Override Iterator<String> names() {
@@ -135,7 +136,6 @@
 			}
 		};
 		tbl.put( "parameters", parameters );
-		add( tbl, "get_parameter_values", String.class );
 		LuanTable headers = new NameTable() {
 
 			@Override Object get(String name) {
@@ -216,14 +216,13 @@
 				final MultiPartInputStream mpis = new MultiPartInputStream(in,contentType,null,null);
 				mpis.setDeleteOnExit(true);
 				parameters = Luan.newTable();
-				LuanTable parts = Luan.newTable();
 				for( Part p : mpis.getParts() ) {
 					final MultiPartInputStream.MultiPart part = (MultiPartInputStream.MultiPart)p;
 					String name = part.getName();
+					Object value;
 					String filename = part.getContentDispositionFilename();
 					if( filename == null ) {
-						String value = new String(part.getBytes());
-						parameters.put(name,value);
+						value = new String(part.getBytes());
 					} else {
 						LuanTable partTbl = Luan.newPropertyTable();
 						partTbl.put("filename",filename);
@@ -238,11 +237,22 @@
 								throw new RuntimeException(e);
 							}
 						} } );
-						parts.put(name,partTbl);
+						value = partTbl;
+					}
+					Object old = parameters.get(name);
+					if( old == null ) {
+						parameters.put(name,value);
+					} else if( old instanceof Object[] ) {
+						Object[] aOld = (Object[])old;
+						Object[] aNew = new Object[aOld.length+1];
+						System.arraycopy(aOld,0,aNew,0,aOld.length);
+						aNew[aOld.length] = value;
+						parameters.put(name,aNew);
+					} else {
+						parameters.put(name,new Object[]{old,value});
 					}
 				}
 				tbl.put( "parameters", parameters );
-				tbl.put( "parts", parts );
 			} catch(IOException e) {
 				throw new RuntimeException(e);
 			} catch(ServletException e) {
@@ -354,11 +364,6 @@
 		return IoLuan.textWriter(response.getWriter());
 	}
 
-	public LuanTable get_parameter_values(String name) {
-		Object[] a = request.getParameterValues(name);
-		return a==null ? null : TableLuan.pack(a);
-	}
-
 	public void send_redirect(String redirectUrl)
 		throws IOException
 	{