Skip to content

Commit

Permalink
Fix GZIP max input in native mode
Browse files Browse the repository at this point in the history
  • Loading branch information
michalvavrik committed Jun 7, 2024
1 parent b2c6551 commit 2db3308
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 33 deletions.
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 {

/**
* 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

0 comments on commit 2db3308

Please sign in to comment.