forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow customization of default content type for Multipart handling
Also changes the default to UTF-8 and apply some minor polish Resolves: quarkusio#19527
- Loading branch information
Showing
11 changed files
with
165 additions
and
28 deletions.
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