-
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
Allow customization of default content type for Multipart handling #19578
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
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
74 changes: 74 additions & 0 deletions
74
...src/test/java/io/quarkus/resteasy/reactive/server/test/multipart/InvalidEncodingTest.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,74 @@ | ||
package io.quarkus.resteasy.reactive.server.test.multipart; | ||
|
||
import static org.hamcrest.CoreMatchers.not; | ||
|
||
import java.net.URISyntaxException; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import org.jboss.resteasy.reactive.MultipartForm; | ||
import org.jboss.resteasy.reactive.RestForm; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
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; | ||
import io.restassured.RestAssured; | ||
import io.restassured.builder.MultiPartSpecBuilder; | ||
import io.restassured.specification.MultiPartSpecification; | ||
|
||
public class InvalidEncodingTest { | ||
|
||
private static final String TEXT_WITH_ACCENTED_CHARACTERS = "Text with UTF-8 accented characters: é à è"; | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest TEST = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(FeedbackBody.class, FeedbackResource.class) | ||
.addAsResource(new StringAsset( | ||
"quarkus.resteasy-reactive.multipart.input-part.default-charset=us-ascii"), | ||
"application.properties")); | ||
|
||
@Test | ||
public void testMultipartEncoding() throws URISyntaxException { | ||
MultiPartSpecification multiPartSpecification = new MultiPartSpecBuilder(TEXT_WITH_ACCENTED_CHARACTERS) | ||
.controlName("content") | ||
// we need to force the content-type to avoid having the charset included | ||
// as we are testing the default behavior when no charset is defined | ||
.header("Content-Type", "text/plain") | ||
.charset(StandardCharsets.UTF_8) | ||
.build(); | ||
|
||
RestAssured | ||
.given() | ||
.multiPart(multiPartSpecification) | ||
.post("/test/multipart-encoding") | ||
.then() | ||
.statusCode(200) | ||
.body(not(TEXT_WITH_ACCENTED_CHARACTERS)); | ||
} | ||
|
||
@Path("/test") | ||
public static class FeedbackResource { | ||
|
||
@POST | ||
@Path("/multipart-encoding") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
@Consumes(MediaType.MULTIPART_FORM_DATA + ";charset=UTF-8") | ||
public String postForm(@MultipartForm final FeedbackBody feedback) { | ||
return feedback.content; | ||
} | ||
} | ||
|
||
public static class FeedbackBody { | ||
@RestForm("content") | ||
public String content; | ||
} | ||
} |
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
38 changes: 38 additions & 0 deletions
38
...java/io/quarkus/resteasy/reactive/server/runtime/ResteasyReactiveServerRuntimeConfig.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,38 @@ | ||
package io.quarkus.resteasy.reactive.server.runtime; | ||
|
||
import java.nio.charset.Charset; | ||
|
||
import io.quarkus.runtime.annotations.ConfigGroup; | ||
import io.quarkus.runtime.annotations.ConfigItem; | ||
import io.quarkus.runtime.annotations.ConfigPhase; | ||
import io.quarkus.runtime.annotations.ConfigRoot; | ||
|
||
@ConfigRoot(name = "resteasy-reactive", phase = ConfigPhase.RUN_TIME) | ||
public class ResteasyReactiveServerRuntimeConfig { | ||
|
||
/** | ||
* Input part configuration. | ||
*/ | ||
@ConfigItem | ||
public MultipartConfigGroup multipart; | ||
|
||
@ConfigGroup | ||
public static class MultipartConfigGroup { | ||
|
||
/** | ||
* Input part configuration. | ||
*/ | ||
@ConfigItem | ||
public InputPartConfigGroup inputPart; | ||
} | ||
|
||
@ConfigGroup | ||
public static class InputPartConfigGroup { | ||
|
||
/** | ||
* Default charset. | ||
*/ | ||
@ConfigItem(defaultValue = "UTF-8") | ||
public Charset defaultCharset; | ||
} | ||
} |
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
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
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.
Does it really need this extra layer of config? It makes for a very long config property.
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 reason I did it was to emulate what we have in RESTEasy Classic. I wanted the full config name to be the same (with the only change being swapping
resteasy
forresteasy-reactive
).