changeset 1266:05934fbf635a

content-type "application/x-www-form-urlencoded; charset=utf-8"
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 30 Sep 2018 19:10:48 -0600
parents 3f4644246e39
children 9fa8b8389578
files src/luan/webserver/Connection.java src/luan/webserver/RequestParser.java src/luan/webserver/Util.java
diffstat 3 files changed, 11 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
diff -r 3f4644246e39 -r 05934fbf635a src/luan/webserver/Connection.java
--- a/src/luan/webserver/Connection.java	Tue Sep 25 19:51:34 2018 -0600
+++ b/src/luan/webserver/Connection.java	Sun Sep 30 19:10:48 2018 -0600
@@ -84,8 +84,11 @@
 	
 					String contentType = (String)request.headers.get("content-type");
 					if( contentType != null ) {
+						contentType = contentType.toLowerCase();
 						if( "application/x-www-form-urlencoded".equals(contentType) ) {
-							parser.parseUrlencoded();
+							parser.parseUrlencoded(null);
+						} else if( "application/x-www-form-urlencoded; charset=utf-8".equals(contentType) ) {
+							parser.parseUrlencoded("utf-8");
 						} else if( contentType.startsWith("multipart/form-data;") ) {
 							parser.parseMultipart();
 						} else if( contentType.equals("application/json; charset=utf-8") ) {
diff -r 3f4644246e39 -r 05934fbf635a src/luan/webserver/RequestParser.java
--- a/src/luan/webserver/RequestParser.java	Tue Sep 25 19:51:34 2018 -0600
+++ b/src/luan/webserver/RequestParser.java	Sun Sep 30 19:10:48 2018 -0600
@@ -19,12 +19,12 @@
 		this.request = request;
 	}
 
-	void parseUrlencoded() throws ParseException {
+	void parseUrlencoded(String charset) throws ParseException, UnsupportedEncodingException {
 		if( request.body == null ) {
 			logger.warn("body is null\n"+request.rawHead);
 			return;
 		}
-		this.parser = new Parser(Util.toString(request.body));
+		this.parser = new Parser(Util.toString(request.body,charset));
 		parseQuery();
 		require( parser.endOfInput() );
 	}
@@ -191,7 +191,7 @@
 
 	private static final String contentTypeStart = "multipart/form-data; boundary=";
 
-	void parseMultipart() throws ParseException {
+	void parseMultipart() throws ParseException, UnsupportedEncodingException {
 		if( request.body == null ) {
 			logger.warn("body is null\n"+request.rawHead);
 			return;
@@ -200,7 +200,7 @@
 		if( !contentType.startsWith(contentTypeStart) )
 			throw new RuntimeException(contentType);
 		String boundary = "--"+contentType.substring(contentTypeStart.length());
-		this.parser = new Parser(Util.toString(request.body));
+		this.parser = new Parser(Util.toString(request.body,null));
 //System.out.println(this.parser.text);
 		require( parser.match(boundary) );
 		boundary = "\r\n" + boundary;
diff -r 3f4644246e39 -r 05934fbf635a src/luan/webserver/Util.java
--- a/src/luan/webserver/Util.java	Tue Sep 25 19:51:34 2018 -0600
+++ b/src/luan/webserver/Util.java	Sun Sep 30 19:10:48 2018 -0600
@@ -32,7 +32,9 @@
 		}
 	}
 
-	static String toString(byte[] a) {
+	static String toString(byte[] a,String charset) throws UnsupportedEncodingException {
+		if( charset != null )
+			return new String(a,charset);
 		char[] ac = new char[a.length];
 		for( int i=0; i<a.length; i++ ) {
 			ac[i] = (char)a[i];