diff src/goodjava/webserver/RequestParser.java @ 1463:fb003c4003dd

better application/json handling
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 30 Mar 2020 18:31:18 -0600
parents 27efb1fcbcb5
children fa066aaa068c
line wrap: on
line diff
--- a/src/goodjava/webserver/RequestParser.java	Sun Mar 29 09:55:59 2020 -0600
+++ b/src/goodjava/webserver/RequestParser.java	Mon Mar 30 18:31:18 2020 -0600
@@ -272,15 +272,12 @@
 	}
 
 	// improve later
-	void parseJson() throws UnsupportedEncodingException {
+	void parseJson(String charset) throws UnsupportedEncodingException {
 		if( request.body == null ) {
 			logger.warn("body is null\n"+request.rawHead);
 			return;
 		}
-		String contentType = (String)request.headers.get("content-type");
-		if( !contentType.equals("application/json; charset=utf-8") )
-			throw new RuntimeException(contentType);
-		String value = new String(request.body,"utf-8");
+		String value = Util.toString(request.body,charset);
 		Util.add(request.parameters,"json",value);
 	}