Mercurial Hosting > luan
comparison src/luan/webserver/RequestParser.java @ 1197:886e14903c1e
better Content-Type handling
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 27 Feb 2018 01:35:09 -0700 |
parents | bd0420fb3dd0 |
children | 9d3835e88204 |
comparison
equal
deleted
inserted
replaced
1196:44491798e431 | 1197:886e14903c1e |
---|---|
1 package luan.webserver; | 1 package luan.webserver; |
2 | 2 |
3 import java.util.List; | 3 import java.util.List; |
4 import java.util.ArrayList; | 4 import java.util.ArrayList; |
5 import org.slf4j.Logger; | |
6 import org.slf4j.LoggerFactory; | |
5 import luan.lib.parser.Parser; | 7 import luan.lib.parser.Parser; |
6 import luan.lib.parser.ParseException; | 8 import luan.lib.parser.ParseException; |
7 | 9 |
8 | 10 |
9 final class RequestParser { | 11 final class RequestParser { |
12 private static final Logger logger = LoggerFactory.getLogger(Connection.class); | |
10 private final Request request; | 13 private final Request request; |
11 private Parser parser; | 14 private Parser parser; |
12 | 15 |
13 RequestParser(Request request) { | 16 RequestParser(Request request) { |
14 this.request = request; | 17 this.request = request; |
15 } | 18 } |
16 | 19 |
17 void parseUrlencoded() throws ParseException { | 20 void parseUrlencoded() throws ParseException { |
21 if( request.body == null ) { | |
22 logger.error("body is null\n"+request.rawHead); | |
23 return; | |
24 } | |
18 this.parser = new Parser(Util.toString(request.body)); | 25 this.parser = new Parser(Util.toString(request.body)); |
19 parseQuery(); | 26 parseQuery(); |
20 require( parser.endOfInput() ); | 27 require( parser.endOfInput() ); |
21 } | 28 } |
22 | 29 |
185 | 192 |
186 | 193 |
187 private static final String contentTypeStart = "multipart/form-data; boundary="; | 194 private static final String contentTypeStart = "multipart/form-data; boundary="; |
188 | 195 |
189 void parseMultipart() throws ParseException { | 196 void parseMultipart() throws ParseException { |
197 if( request.body == null ) { | |
198 logger.error("body is null\n"+request.rawHead); | |
199 return; | |
200 } | |
190 String contentType = (String)request.headers.get("content-type"); | 201 String contentType = (String)request.headers.get("content-type"); |
191 if( !contentType.startsWith(contentTypeStart) ) | 202 if( !contentType.startsWith(contentTypeStart) ) |
192 throw new RuntimeException(contentType); | 203 throw new RuntimeException(contentType); |
193 String boundary = "--"+contentType.substring(contentTypeStart.length()); | 204 String boundary = "--"+contentType.substring(contentTypeStart.length()); |
194 this.parser = new Parser(Util.toString(request.body)); | 205 this.parser = new Parser(Util.toString(request.body)); |