diff src/luan/webserver/RequestParser.java @ 1259:e8020216dee7

add Luan.to_luan and fix multipart/form-data
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 23 Sep 2018 17:58:40 -0600
parents e4d7a3114fa8
children 05934fbf635a
line wrap: on
line diff
--- a/src/luan/webserver/RequestParser.java	Thu Sep 20 22:11:11 2018 -0600
+++ b/src/luan/webserver/RequestParser.java	Sun Sep 23 17:58:40 2018 -0600
@@ -201,6 +201,7 @@
 			throw new RuntimeException(contentType);
 		String boundary = "--"+contentType.substring(contentTypeStart.length());
 		this.parser = new Parser(Util.toString(request.body));
+//System.out.println(this.parser.text);
 		require( parser.match(boundary) );
 		boundary = "\r\n" + boundary;
 		while( !parser.match("--\r\n") ) {
@@ -213,12 +214,15 @@
 				filename = quotedString();
 				require( parser.match("\r\n") );
 				require( parser.match("Content-Type: ") );
-				if( parser.match("application/octet-stream") ) {
+				int start = parser.currentIndex();
+				if( parser.match("application/") ) {
 					isBinary = true;
-				} else if( parser.match("text/plain") ) {
+				} else if( parser.match("text/") ) {
 					isBinary = false;
 				} else
 					throw new ParseException(parser,"bad file content-type");
+				while( parser.inCharRange('a','z') || parser.anyOf("-.") );
+				contentType = parser.textFrom(start);
 			}
 			require( parser.match("\r\n") );
 			require( parser.match("\r\n") );
@@ -231,7 +235,7 @@
 				Util.add(request.parameters,name,value);
 			} else {
 				Object content = isBinary ? Util.toBytes(value) : value;
-				Request.MultipartFile mf = new Request.MultipartFile(filename,content);
+				Request.MultipartFile mf = new Request.MultipartFile(filename,contentType,content);
 				Util.add(request.parameters,name,mf);
 			}
 			require( parser.match(boundary) );