comparison 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
comparison
equal deleted inserted replaced
1462:bfbf9c9c1586 1463:fb003c4003dd
270 throw new ParseException(parser,e); 270 throw new ParseException(parser,e);
271 } 271 }
272 } 272 }
273 273
274 // improve later 274 // improve later
275 void parseJson() throws UnsupportedEncodingException { 275 void parseJson(String charset) throws UnsupportedEncodingException {
276 if( request.body == null ) { 276 if( request.body == null ) {
277 logger.warn("body is null\n"+request.rawHead); 277 logger.warn("body is null\n"+request.rawHead);
278 return; 278 return;
279 } 279 }
280 String contentType = (String)request.headers.get("content-type"); 280 String value = Util.toString(request.body,charset);
281 if( !contentType.equals("application/json; charset=utf-8") )
282 throw new RuntimeException(contentType);
283 String value = new String(request.body,"utf-8");
284 Util.add(request.parameters,"json",value); 281 Util.add(request.parameters,"json",value);
285 } 282 }
286 283
287 } 284 }