comparison src/goodjava/webserver/Connection.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 471ef3e6a84e
comparison
equal deleted inserted replaced
1462:bfbf9c9c1586 1463:fb003c4003dd
83 } 83 }
84 84
85 String contentType = (String)request.headers.get("content-type"); 85 String contentType = (String)request.headers.get("content-type");
86 if( contentType != null ) { 86 if( contentType != null ) {
87 contentType = contentType.toLowerCase(); 87 contentType = contentType.toLowerCase();
88 if( "application/x-www-form-urlencoded".equals(contentType) ) { 88 if( contentType.equals("application/x-www-form-urlencoded") ) {
89 parser.parseUrlencoded(null); 89 parser.parseUrlencoded(null);
90 } else if( "application/x-www-form-urlencoded; charset=utf-8".equals(contentType) ) { 90 } else if( contentType.equals("application/x-www-form-urlencoded; charset=utf-8") ) {
91 parser.parseUrlencoded("utf-8"); 91 parser.parseUrlencoded("utf-8");
92 } else if( contentType.startsWith("multipart/form-data;") ) { 92 } else if( contentType.startsWith("multipart/form-data;") ) {
93 parser.parseMultipart(); 93 parser.parseMultipart();
94 } else if( contentType.equals("application/json") ) {
95 parser.parseJson(null);
94 } else if( contentType.equals("application/json; charset=utf-8") ) { 96 } else if( contentType.equals("application/json; charset=utf-8") ) {
95 parser.parseJson(); 97 parser.parseJson("utf-8");
96 } else { 98 } else {
97 logger.info("unknown request content-type: "+contentType); 99 logger.info("unknown request content-type: "+contentType);
98 } 100 }
99 } 101 }
100 102