Skip to content

Commit

Permalink
[UNDERTOW-2337] Also verify if the value of the part can be retrieved…
Browse files Browse the repository at this point in the history
… as a parameter

Signed-off-by: Flavia Rainone <frainone@redhat.com>
  • Loading branch information
fl4via committed Feb 12, 2024
1 parent df5c0ad commit 765f69b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Enumeration;
import java.util.TreeSet;

import io.undertow.util.Headers;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -65,6 +66,17 @@ protected void doPost(final HttpServletRequest req, final HttpServletResponse re
Collection<String> headerNames = new TreeSet<>(part.getHeaderNames());
for (String header : headerNames) {
writer.println(header + ": " + part.getHeader(header));
if (header.equals(Headers.CONTENT_DISPOSITION_STRING)) {
final String parameterValue = part.getHeader(header);
String parameterName = parameterValue.substring(parameterValue.indexOf("name=") + "name=\"".length());
parameterName = parameterName.substring(0, parameterName.indexOf('\"'));
final String[] values = req.getParameterValues(parameterName);
if (values != null) {
for (String value: values) {
writer.println("value: " + value);
}
}
}
}
writer.println("size: " + part.getSize());
writer.println("content: " + FileUtils.readFile(part.getInputStream()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public void testMultiPartRequest() throws IOException {
"filename: null\r\n" +
"content-type: null\r\n" +
"Content-Disposition: form-data; name=\"formValue\"\r\n" +
"value: myValue\r\n" +
"size: 7\r\n" +
"content: myValue\r\n" +
"name: file\r\n" +
Expand Down Expand Up @@ -163,6 +164,7 @@ public void testMultiPartRequestWithAddedServlet() throws IOException {
"filename: null\r\n" +
"content-type: null\r\n" +
"Content-Disposition: form-data; name=\"formValue\"\r\n" +
"value: myValue\r\n" +
"size: 7\r\n" +
"content: myValue\r\n" +
"name: file\r\n" +
Expand Down Expand Up @@ -242,6 +244,7 @@ public void testMultiPartRequestUtf8CharsetInPart() throws IOException {
"filename: null\r\n" +
"content-type: text/plain; charset=UTF-8\r\n" +
"Content-Disposition: form-data; name=\"formValue\"\r\n" +
"value: " + "myValue" + '\u00E5' + "\r\n" +
"Content-Transfer-Encoding: 8bit\r\n" +
"Content-Type: text/plain; charset=UTF-8\r\n" +
"size: 9\r\n" +
Expand Down Expand Up @@ -275,6 +278,7 @@ public void testMultiPartRequestBigPostForm() throws IOException {
"filename: null\r\n" +
"content-type: null\r\n" +
"Content-Disposition: form-data; name=\"formValue\"\r\n" +
"value: " + myValue + "\r\n" +
"size: " + myValue.getBytes(StandardCharsets.UTF_8).length + "\r\n" +
"content: " + myValue + "\r\n" +
"name: file\r\n" +
Expand Down

0 comments on commit 765f69b

Please sign in to comment.