-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Expand types which are considered text in multipart handling #38810
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
.../io/quarkus/resteasy/reactive/server/test/multipart/MultipartTextWithoutFilenameTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package io.quarkus.resteasy.reactive.server.test.multipart; | ||
|
||
import static io.restassured.RestAssured.given; | ||
|
||
import java.io.IOException; | ||
import java.util.function.Supplier; | ||
|
||
import jakarta.ws.rs.FormParam; | ||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
|
||
import org.jboss.resteasy.reactive.RestResponse; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class MultipartTextWithoutFilenameTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest test = new QuarkusUnitTest() | ||
.setArchiveProducer(new Supplier<>() { | ||
@Override | ||
public JavaArchive get() { | ||
return ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(Resource.class); | ||
} | ||
}); | ||
|
||
@Test | ||
public void test() throws IOException { | ||
given() | ||
.contentType("multipart/form-data") | ||
.multiPart("firstParam", "{\"id\":\"myId\",\"name\":\"myName\"}", "application/json") | ||
.when() | ||
.post("/test") | ||
.then() | ||
.statusCode(200); | ||
} | ||
|
||
@Path("/test") | ||
public static class Resource { | ||
|
||
@POST | ||
public RestResponse<Void> testMultipart(@FormParam("firstParam") final String firstParam, | ||
@FormParam("secondParam") final String secondParam) { | ||
return RestResponse.ok(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh, I wonder if there's any more formal definition of what can be turned into a text.
Also, I wonder how this all compares to "toplevel" body parsing.
In theory, multipart members and body entities should now have the same parsing mechanism, in that they each have an encoding, content type, and go via
MessageBodyReader
for deserialisation, which is what allows us to have not just primitive types but also JSON/XML deserialisation.This logic appears to sit before we look up the right
MessageBodyReader
for the deserialisation. I wonder why we have this. Perhaps everything at this point should be read asbyte[]
(well, and associated with their content-type), and then later when we figure out whether to deserialise this into aString
orJsonObject
orPerson
entity, we use the same binary data?Here we're accepting "deserialising" XML/JSON/YAML into
String
which means: no deserialisation, just give them "raw" (still respecting the encoding). For a mime part. Do we accept the same for a toplevel http request body? I think we do. But I wonder if we also limit it there for XML/JSON/YAML or if we have another sort of check of text-like, or… "String-convertible".There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whole thing is weird and this is only needed to try to decide what type of part of this is (see calls to
FormData#add
).I really don't like what we are doing, but I don't have any ideas to make it better.