changeset 1198:9d3835e88204

better query handling
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 27 Feb 2018 21:28:24 -0700
parents 886e14903c1e
children 3995cbe5b00a
files src/luan/webserver/Connection.java src/luan/webserver/RequestParser.java
diffstat 2 files changed, 14 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
diff -r 886e14903c1e -r 9d3835e88204 src/luan/webserver/Connection.java
--- a/src/luan/webserver/Connection.java	Tue Feb 27 01:35:09 2018 -0700
+++ b/src/luan/webserver/Connection.java	Tue Feb 27 21:28:24 2018 -0700
@@ -89,7 +89,7 @@
 						} else if( contentType.startsWith("multipart/form-data;") ) {
 							parser.parseMultipart();
 						} else {
-							logger.warn("unknown content type: "+contentType);
+							logger.warn("unknown request content-type: "+contentType);
 						}
 					}
 				}
diff -r 886e14903c1e -r 9d3835e88204 src/luan/webserver/RequestParser.java
--- a/src/luan/webserver/RequestParser.java	Tue Feb 27 01:35:09 2018 -0700
+++ b/src/luan/webserver/RequestParser.java	Tue Feb 27 21:28:24 2018 -0700
@@ -9,7 +9,7 @@
 
 
 final class RequestParser {
-	private static final Logger logger = LoggerFactory.getLogger(Connection.class);
+	private static final Logger logger = LoggerFactory.getLogger(RequestParser.class);
 	private final Request request;
 	private Parser parser;
 
@@ -19,7 +19,7 @@
 
 	void parseUrlencoded() throws ParseException {
 		if( request.body == null ) {
-			logger.error("body is null\n"+request.rawHead);
+			logger.warn("body is null\n"+request.rawHead);
 			return;
 		}
 		this.parser = new Parser(Util.toString(request.body));
@@ -74,27 +74,26 @@
 	}
 
 	private void parseQuery() throws ParseException {
-		while(true) {
-			while( parser.match('&') );
+		do {
 			int start = parser.currentIndex();
-			if( !queryChar() )
-				return;
 			while( queryChar() );
 			String name = Util.urlDecode( parser.textFrom(start) );
-			String value;
+			String value = null;
 			if( parser.match('=') ) {
 				start = parser.currentIndex();
-				while( queryChar() );
+				while( queryChar() || parser.match('=') );
 				value = Util.urlDecode( parser.textFrom(start) );
-			} else {
-				value = "";
 			}
-			Util.add(request.parameters,name,value);
-		}
+			if( name.length() > 0 || value != null ) {
+				if( value==null )
+					value = "";
+				Util.add(request.parameters,name,value);
+			}
+		} while( parser.match('&') );
 	}
 
 	private boolean queryChar() {
-		return safePathChar() || parser.anyOf("?\\\"");
+		return parser.noneOf("=&# \t\n\f\r\u000b");
 	}
 
 	// where did I get this?
@@ -195,7 +194,7 @@
 
 	void parseMultipart() throws ParseException {
 		if( request.body == null ) {
-			logger.error("body is null\n"+request.rawHead);
+			logger.warn("body is null\n"+request.rawHead);
 			return;
 		}
 		String contentType = (String)request.headers.get("content-type");