Add a property to disable auto-configuration of GzipFilter
Closes gh-2776
This commit is contained in:
parent
c8c2eea03e
commit
212520fa15
|
@ -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("/*");
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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])
|
||||
|
|
Loading…
Reference in New Issue