comparison src/luan/webserver/Connection.java @ 1197:886e14903c1e

better Content-Type handling
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 27 Feb 2018 01:35:09 -0700
parents 44491798e431
children 9d3835e88204
comparison
equal deleted inserted replaced
1196:44491798e431 1197:886e14903c1e
58 a = a2; 58 a = a2;
59 left = a.length - size; 59 left = a.length - size;
60 } 60 }
61 } 61 }
62 String rawHead = new String(a,0,endOfHeader); 62 String rawHead = new String(a,0,endOfHeader);
63 //System.out.println(rawHead); 63 //System.out.println(rawHead);
64 request.rawHead = rawHead; 64 request.rawHead = rawHead;
65 RequestParser parser = new RequestParser(request); 65 RequestParser parser = new RequestParser(request);
66 parser.parseHead(); 66 parser.parseHead();
67 67
68 String lenStr = (String)request.headers.get("content-length"); 68 String lenStr = (String)request.headers.get("content-length");
77 throw new IOException("unexpected end of input at "+size); 77 throw new IOException("unexpected end of input at "+size);
78 } 78 }
79 size += n; 79 size += n;
80 } 80 }
81 request.body = body; 81 request.body = body;
82 //System.out.println(new String(request.body)); 82 //System.out.println(new String(request.body));
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 if( request.body == null ) { 87 if( "application/x-www-form-urlencoded".equals(contentType) ) {
88 logger.error("body is null\n"+request.rawHead); 88 parser.parseUrlencoded();
89 } else if( contentType.startsWith("multipart/form-data;") ) {
90 parser.parseMultipart();
89 } else { 91 } else {
90 if( "application/x-www-form-urlencoded".equals(contentType) ) { 92 logger.warn("unknown content type: "+contentType);
91 parser.parseUrlencoded();
92 } else if( contentType.startsWith("multipart/form-data;") ) {
93 parser.parseMultipart();
94 } else {
95 logger.error("unknown content type: "+contentType);
96 }
97 } 93 }
98 } 94 }
99 } 95 }
100 response = server.handler.handle(request); 96 response = server.handler.handle(request);
101 } catch(ParseException e) { 97 } catch(ParseException e) {