changeset 1145:12ececf30597

webserver - minor
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 31 Jan 2018 01:43:50 -0700
parents ae0a048f3bc7
children 2dda3c92a473
files src/luan/webserver/Connection.java src/luan/webserver/RequestParser.java
diffstat 2 files changed, 10 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
diff -r ae0a048f3bc7 -r 12ececf30597 src/luan/webserver/Connection.java
--- a/src/luan/webserver/Connection.java	Wed Jan 31 00:29:50 2018 -0700
+++ b/src/luan/webserver/Connection.java	Wed Jan 31 01:43:50 2018 -0700
@@ -79,12 +79,17 @@
 					request.body = new String(body);
 //System.out.println(request.body);
 				}
-	
-				if( request.method.equals("POST") ) {
+
+				String contentType = request.headers.get("Content-Type");
+				if( contentType != null ) {
 					if( request.body == null ) {
-						logger.error("post body is null");
+						logger.error("body is null");
 					} else {
-						parser.parsePost();
+						if( "application/x-www-form-urlencoded".equals(contentType) ) {
+							parser.parseUrlencoded();
+						} else {
+							logger.warn("unknown content type: "+contentType);
+						}
 					}
 				}
 			}
diff -r ae0a048f3bc7 -r 12ececf30597 src/luan/webserver/RequestParser.java
--- a/src/luan/webserver/RequestParser.java	Wed Jan 31 00:29:50 2018 -0700
+++ b/src/luan/webserver/RequestParser.java	Wed Jan 31 01:43:50 2018 -0700
@@ -16,7 +16,7 @@
 		this.request = request;
 	}
 
-	void parsePost() throws ParseException {
+	void parseUrlencoded() throws ParseException {
 		this.parser = new Parser(request.body);
 		parseQuery();
 		require( parser.endOfInput() );