<form action="/" ENCTYPE="multipart/form-data" method="POST" name="wibble">
foo:<input type="text" name="foo"/><br>
bar:<input type="text" name="bar"/><br>
choose a file to upload:<input type="file" name="myfile"/><br>
<input type="submit"/>
</form>vertx.createHttpServer()
.requestHandler(req -> {
final String contentType = req.getHeader(HttpHeaders.CONTENT_TYPE);
Boolean isMultipart = contentType != null && contentType.contains("multipart/form-data");
if (isMultipart) {
req.setExpectMultipart(true);
String foo = req.getFormAttribute("foo");
System.out.println(foo); // NULL value
req.uploadHandler(upload -> {
upload.handler(buff -> {
System.out.println("data");
});
upload.endHandler(r -> {
System.out.println("enddata");
});
});
req.endHandler(fin -> {
String foo = req.getFormAttribute("foo");
System.out.println(foo); // good value
});
} else {
req.response().sendFile("index.html");
}
req.exceptionHandler(th -> {
System.out.println("fail to handle request");
});
})
.listen(8080);<form action="/" ENCTYPE="multipart/form-data" method="POST" name="wibble">
token:<input type="text" name="token"/><br>
choose a file to upload:<input type="file" name="myfile"/><br>
<input type="submit"/>
</form>
regarding API Tokens, you want to abort the request ASAP, in that case it would make more sense to use an HTTP header for it, either the `Authorization` or some custom `X-APITOKEN` for example so the processing can be stopped before handling the body, or if you need to use HTML forms, a path parameter/variable.
This way it could be even be stopped by a proxy to the application if needed...
Now regarding the proposed fixes, the 1st one would have some impact but would work as expected imho. While the second one would only be useful if you're handling the body yourself (like in your example), where you can check the value of the form attributes once a buffer is delivered to the handler. For other users, such as everyone using vert.x web this would not change at all the current behavior and it wouldn't be exposed either.
My concern with 2 is that knowing when a new param has been parsed is not deterministic since there is no handler for it, so depending on the handler where you're requesting the parsed attribute the value can be either null or not null...