Skip to content
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

Fix RESTEasy Classic GZIP max input in native mode #41054

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,14 @@
import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem;
import io.quarkus.deployment.util.ServiceUtil;
import io.quarkus.resteasy.common.runtime.ResteasyCommonConfig;
import io.quarkus.resteasy.common.runtime.ResteasyInjectorFactoryRecorder;
import io.quarkus.resteasy.common.runtime.config.ResteasyConfigBuilder;
import io.quarkus.resteasy.common.runtime.providers.ServerFormUrlEncodedProvider;
import io.quarkus.resteasy.common.spi.ResteasyConfigBuildItem;
import io.quarkus.resteasy.common.spi.ResteasyDotNames;
import io.quarkus.resteasy.common.spi.ResteasyJaxrsProviderBuildItem;
import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.quarkus.runtime.configuration.MemorySize;

public class ResteasyCommonProcessor {

Expand Down Expand Up @@ -102,31 +99,6 @@ public class ResteasyCommonProcessor {

private ResteasyCommonConfig resteasyCommonConfig;

@ConfigRoot(name = "resteasy")
public static final class ResteasyCommonConfig {
/**
* Enable gzip support for REST
*/
public ResteasyCommonConfigGzip gzip;
}

@ConfigGroup
public static final class ResteasyCommonConfigGzip {
/**
* If gzip is enabled
*/
@ConfigItem
public boolean enabled;
/**
* Maximum deflated file bytes size
* <p>
* If the limit is exceeded, Resteasy will return Response
* with status 413("Request Entity Too Large")
*/
@ConfigItem(defaultValue = "10M")
public MemorySize maxInput;
}

@BuildStep
void addStaticInitConfigSourceProvider(
Capabilities capabilities,
Expand Down Expand Up @@ -164,7 +136,7 @@ void disableDefaultExceptionMapper(BuildProducer<SystemPropertyBuildItem> system
@BuildStep
void setupGzipProviders(BuildProducer<ResteasyJaxrsProviderBuildItem> providers) {
// If GZIP support is enabled, enable it
if (resteasyCommonConfig.gzip.enabled) {
if (resteasyCommonConfig.gzip().enabled()) {
providers.produce(new ResteasyJaxrsProviderBuildItem(AcceptEncodingGZIPFilter.class.getName()));
providers.produce(new ResteasyJaxrsProviderBuildItem(GZIPDecodingInterceptor.class.getName()));
providers.produce(new ResteasyJaxrsProviderBuildItem(GZIPEncodingInterceptor.class.getName()));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.quarkus.resteasy.common.runtime;

import static io.quarkus.runtime.annotations.ConfigPhase.BUILD_AND_RUN_TIME_FIXED;

import io.quarkus.runtime.annotations.ConfigRoot;
import io.quarkus.runtime.configuration.MemorySize;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithDefault;

@ConfigRoot(phase = BUILD_AND_RUN_TIME_FIXED)
@ConfigMapping(prefix = "quarkus.resteasy")
public interface ResteasyCommonConfig {
michalvavrik marked this conversation as resolved.
Show resolved Hide resolved

/**
* Enable gzip support for REST
*/
ResteasyCommonConfigGzip gzip();

interface ResteasyCommonConfigGzip {
/**
* If gzip is enabled
*/
@WithDefault("false")
boolean enabled();

/**
* Maximum deflated file bytes size
* <p>
* If the limit is exceeded, Resteasy will return Response
* with status 413("Request Entity Too Large")
*/
@WithDefault("10M")
MemorySize maxInput();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@
import io.quarkus.gizmo.Gizmo;
import io.quarkus.jaxrs.spi.deployment.AdditionalJaxRsResourceMethodAnnotationsBuildItem;
import io.quarkus.resteasy.common.deployment.JaxrsProvidersToRegisterBuildItem;
import io.quarkus.resteasy.common.deployment.ResteasyCommonProcessor.ResteasyCommonConfig;
import io.quarkus.resteasy.common.runtime.QuarkusInjectorFactory;
import io.quarkus.resteasy.common.runtime.ResteasyCommonConfig;
import io.quarkus.resteasy.common.spi.ResteasyDotNames;
import io.quarkus.resteasy.server.common.runtime.QuarkusResteasyDeployment;
import io.quarkus.resteasy.server.common.spi.AdditionalJaxRsResourceDefiningAnnotationBuildItem;
Expand Down Expand Up @@ -421,9 +421,9 @@ public void build(
deploymentCustomizer.getConsumer().accept(deployment);
}

if (commonConfig.gzip.enabled) {
if (commonConfig.gzip().enabled()) {
resteasyInitParameters.put(ResteasyContextParameters.RESTEASY_GZIP_MAX_INPUT,
Long.toString(commonConfig.gzip.maxInput.asLongValue()));
Long.toString(commonConfig.gzip().maxInput().asLongValue()));
}
resteasyInitParameters.put(ResteasyContextParameters.RESTEASY_UNWRAPPED_EXCEPTIONS,
ArcUndeclaredThrowableException.class.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public Set<String> getInitParameterNames() {
}

private static Optional<String> getGzipMaxInput(Config config) {
if (config.getOptionalValue("resteasy.gzip.max.input", String.class).isPresent()) {
// resteasy-specific properties have priority
return Optional.empty();
}
michalvavrik marked this conversation as resolved.
Show resolved Hide resolved

Optional<MemorySize> rawValue = config.getOptionalValue("quarkus.resteasy.gzip.max-input", MemorySize.class);

if (rawValue.isEmpty()) {
Expand Down
Loading