diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/GzipFilterAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/GzipFilterAutoConfiguration.java index eb12a29860..e50fe1ec78 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/GzipFilterAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/GzipFilterAutoConfiguration.java @@ -20,6 +20,7 @@ import org.eclipse.jetty.servlets.GzipFilter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.embedded.FilterRegistrationBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; @@ -40,6 +41,7 @@ public class GzipFilterAutoConfiguration { private GzipFilterProperties properties; @Bean + @ConditionalOnProperty(prefix = "spring.http.gzip", name = "enabled", matchIfMissing = true) public FilterRegistrationBean gzipFilter() { FilterRegistrationBean registration = new FilterRegistrationBean(new GzipFilter()); registration.addUrlPatterns("/*"); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/GzipFilterAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/GzipFilterAutoConfigurationTests.java index ec6d0e928d..727049577a 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/GzipFilterAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/GzipFilterAutoConfigurationTests.java @@ -24,6 +24,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; /** @@ -102,6 +103,13 @@ public class GzipFilterAutoConfigurationTests { equalTo("vary-header-value")); } + @Test + public void filterCanBeDisabled() { + createAndRefreshContext("spring.http.gzip.enabled:false"); + assertThat(this.context.getBeanNamesForType(FilterRegistrationBean.class).length, + is(equalTo(0))); + } + private void createAndRefreshContext(String... pairs) { this.context = new AnnotationConfigApplicationContext(); EnvironmentTestUtils.addEnvironment(this.context, pairs); diff --git a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index 3bd9f7e33c..3a6e20a9e6 100644 --- a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -115,15 +115,16 @@ content into your application; rather pick only the properties that you need. # HTTP response compression ({sc-spring-boot-autoconfigure}/web/GzipFilterProperties.{sc-ext}[GzipFilterProperties]) spring.http.gzip.bufferSize= # size of the output buffer in bytes - spring.http.gzip.minGzipSize= # minimum content length required for compression to occur spring.http.gzip.deflateCompressionLevel= # the level used for deflate compression (0-9) spring.http.gzip.deflateNoWrap= # noWrap setting for deflate compression (true or false) - spring.http.gzip.methods= # comma-separated list of HTTP methods for which compression is enabled - spring.http.gzip.mimeTypes= # comma-separated list of MIME types which should be compressed + spring.http.gzip.enabled=true # enable gzip filter support spring.http.gzip.excludedAgents= # comma-separated list of user agents to exclude from compression spring.http.gzip.excludedAgentPatterns= # comma-separated list of regular expression patterns to control user agents excluded from compression spring.http.gzip.excludedPaths= # comma-separated list of paths to exclude from compression spring.http.gzip.excludedPathPatterns= # comma-separated list of regular expression patterns to control the paths that are excluded from compression + spring.http.gzip.methods= # comma-separated list of HTTP methods for which compression is enabled + spring.http.gzip.mimeTypes= # comma-separated list of MIME types which should be compressed + spring.http.gzip.minGzipSize= # minimum content length required for compression to occur spring.http.gzip.vary= # Vary header to be sent on responses that may be compressed # JACKSON ({sc-spring-boot-autoconfigure}/jackson/JacksonProperties.{sc-ext}[JacksonProperties])