Mercurial Hosting > luan
comparison src/luan/webserver/RequestParser.java @ 1266:05934fbf635a
content-type "application/x-www-form-urlencoded; charset=utf-8"
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 30 Sep 2018 19:10:48 -0600 |
parents | e8020216dee7 |
children | c214cd0413dd |
comparison
equal
deleted
inserted
replaced
1265:3f4644246e39 | 1266:05934fbf635a |
---|---|
17 | 17 |
18 RequestParser(Request request) { | 18 RequestParser(Request request) { |
19 this.request = request; | 19 this.request = request; |
20 } | 20 } |
21 | 21 |
22 void parseUrlencoded() throws ParseException { | 22 void parseUrlencoded(String charset) throws ParseException, UnsupportedEncodingException { |
23 if( request.body == null ) { | 23 if( request.body == null ) { |
24 logger.warn("body is null\n"+request.rawHead); | 24 logger.warn("body is null\n"+request.rawHead); |
25 return; | 25 return; |
26 } | 26 } |
27 this.parser = new Parser(Util.toString(request.body)); | 27 this.parser = new Parser(Util.toString(request.body,charset)); |
28 parseQuery(); | 28 parseQuery(); |
29 require( parser.endOfInput() ); | 29 require( parser.endOfInput() ); |
30 } | 30 } |
31 | 31 |
32 void parseHead() throws ParseException { | 32 void parseHead() throws ParseException { |
189 } | 189 } |
190 | 190 |
191 | 191 |
192 private static final String contentTypeStart = "multipart/form-data; boundary="; | 192 private static final String contentTypeStart = "multipart/form-data; boundary="; |
193 | 193 |
194 void parseMultipart() throws ParseException { | 194 void parseMultipart() throws ParseException, UnsupportedEncodingException { |
195 if( request.body == null ) { | 195 if( request.body == null ) { |
196 logger.warn("body is null\n"+request.rawHead); | 196 logger.warn("body is null\n"+request.rawHead); |
197 return; | 197 return; |
198 } | 198 } |
199 String contentType = (String)request.headers.get("content-type"); | 199 String contentType = (String)request.headers.get("content-type"); |
200 if( !contentType.startsWith(contentTypeStart) ) | 200 if( !contentType.startsWith(contentTypeStart) ) |
201 throw new RuntimeException(contentType); | 201 throw new RuntimeException(contentType); |
202 String boundary = "--"+contentType.substring(contentTypeStart.length()); | 202 String boundary = "--"+contentType.substring(contentTypeStart.length()); |
203 this.parser = new Parser(Util.toString(request.body)); | 203 this.parser = new Parser(Util.toString(request.body,null)); |
204 //System.out.println(this.parser.text); | 204 //System.out.println(this.parser.text); |
205 require( parser.match(boundary) ); | 205 require( parser.match(boundary) ); |
206 boundary = "\r\n" + boundary; | 206 boundary = "\r\n" + boundary; |
207 while( !parser.match("--\r\n") ) { | 207 while( !parser.match("--\r\n") ) { |
208 require( parser.match("\r\n") ); | 208 require( parser.match("\r\n") ); |