-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve consistency of looking up query and form parameters #12277
Comments
Don't forget String boundary = MultiPart.extractBoundary(contentType);
MultiPartFormData.Parser formData = new MultiPartFormData.Parser(boundary);
formData.setFilesDirectory(workDir);
// we are assuming a simple form with no binary data (like a file upload)
Map<String, String> form = new HashMap<>();
// May block waiting for multipart form data.
try (MultiPartFormData.Parts parts = formData.parse(request).join())
{
parts.forEach(part ->
{
if (StringUtil.isNotBlank(part.getFileName()))
return; // skip files
String value = part.getContentAsString(StandardCharsets.UTF_8);
form.put(part.getName(), value);
});
} |
Right now ...
There are also parsers in Jetty for |
Form Field parsing is done by Whilst the parsing itself is the same, there are significant different concerns of needing to be able to read a form asynchronously in bytes vs having the full query available as a string. Perhaps the query string could be converted back to bytes, wrapped as a chunk and the normal form parser used... but that is a lot of extra work for a very frequent component of requests. So whilst I do not like code duplication.... performance is probably more important in this case and I think |
At this point, I care more about discoverability than invocation styles (though, yes, long-term it would be nice to make that consistent as well). |
@cowwoc So tell us how you go about discovery? You want a class to parse form fields, so are you searching javadoc, other documentation or just looking for a class that is named appropriately? In this case, I'm guessing it is probably the |
I was hoping to look at the |
When using your IDE, does it show the static methods on Request (like |
I'm using IntelliJ, and yes it shows the static methods as well. To find the method in question, I typed This is how I usually start my search for new methods. |
Jetty version(s)
12
Enhancement Description
To look up query parameters, one has to invoke
Request.extractQueryParameters(Request)
.To look up form parameters, one has to invoke
FormFields.from(Request)
.I only figured out the latter by digging into Jetty's source-code.
Ideally, the two APIs should be similar, accessible from the same class, and easily discoverable.
The text was updated successfully, but these errors were encountered: