|
215 | 215 | import java.util.concurrent.Executor; |
216 | 216 | import java.util.stream.Collectors; |
217 | 217 |
|
218 | | -import io.undertow.server.handlers.form.FormDataParser; |
| 218 | +import io.undertow.server.handlers.form.*; |
219 | 219 | import org.jooby.Cookie; |
220 | 220 | import org.jooby.MediaType; |
221 | 221 | import org.jooby.Router; |
|
233 | 233 |
|
234 | 234 | import io.undertow.server.BlockingHttpExchange; |
235 | 235 | import io.undertow.server.HttpServerExchange; |
236 | | -import io.undertow.server.handlers.form.FormData; |
237 | 236 | import io.undertow.server.handlers.form.FormData.FormValue; |
238 | | -import io.undertow.server.handlers.form.FormEncodedDataDefinition; |
239 | | -import io.undertow.server.handlers.form.MultiPartParserDefinition; |
240 | 237 | import io.undertow.util.AttachmentKey; |
241 | 238 | import io.undertow.util.HeaderValues; |
242 | 239 | import io.undertow.util.HttpString; |
@@ -410,25 +407,22 @@ private FormData parseForm() { |
410 | 407 | try { |
411 | 408 | String tmpdir = conf.getString("application.tmpdir"); |
412 | 409 | String charset = conf.getString("application.charset"); |
413 | | - String value = exchange.getRequestHeaders().getFirst("Content-Type"); |
414 | | - if (value != null) { |
415 | | - MediaType type = MediaType.valueOf(value); |
416 | | - if (MediaType.form.name().equals(type.name())) { |
417 | | - blocking.get(); |
418 | | - form = new FormEncodedDataDefinition() |
419 | | - .setDefaultEncoding(charset) |
420 | | - .create(exchange) |
421 | | - .parseBlocking(); |
422 | | - } else if (MediaType.multipart.name().equals(type.name())) { |
423 | | - blocking.get(); |
424 | | - form = new MultiPartParserDefinition() |
| 410 | + |
| 411 | + FormEncodedDataDefinition encodedParser = new FormEncodedDataDefinition().setDefaultEncoding(charset); |
| 412 | + MultiPartParserDefinition multiPartParser = new MultiPartParserDefinition() |
425 | 413 | .setTempFileLocation(new File(tmpdir).toPath()) |
426 | | - .setDefaultEncoding(charset) |
427 | | - .create(exchange) |
428 | | - .parseBlocking(); |
429 | | - } |
430 | | - } |
431 | | - } catch (IOException x) { |
| 414 | + .setDefaultEncoding(charset); |
| 415 | + blocking.get(); |
| 416 | + FormDataParser parser = FormParserFactory |
| 417 | + .builder(false) |
| 418 | + .addParser(encodedParser) |
| 419 | + .addParser(multiPartParser) |
| 420 | + .build() |
| 421 | + .createParser(exchange); |
| 422 | + |
| 423 | + form = parser != null ? parser.parseBlocking() : NO_FORM; |
| 424 | + } catch (IOException iox) { |
| 425 | + throw new IllegalArgumentException("Bad Request...", iox); |
432 | 426 | } |
433 | 427 | } |
434 | 428 | return form; |
|
0 commit comments