Fix Gzip filter properties
Fix `excludeAgentPatterns`, `excludePaths` and `excludePathPatterns` properties. Introduce `excludedMimeTypes` property. Fixes gh-3042
This commit is contained in:
parent
676b7d713a
commit
160f2d341f
|
|
@ -30,6 +30,7 @@ import org.springframework.util.StringUtils;
|
||||||
* Properties for configuring {@link GzipFilter}.
|
* Properties for configuring {@link GzipFilter}.
|
||||||
*
|
*
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
|
* @author Stephane Nicoll
|
||||||
* @since 1.2.2
|
* @since 1.2.2
|
||||||
*/
|
*/
|
||||||
@ConfigurationProperties(prefix = "spring.http.gzip")
|
@ConfigurationProperties(prefix = "spring.http.gzip")
|
||||||
|
|
@ -67,6 +68,11 @@ public class GzipFilterProperties {
|
||||||
*/
|
*/
|
||||||
private List<MimeType> mimeTypes;
|
private List<MimeType> mimeTypes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Comma-separated list of MIME types to exclude from compression.
|
||||||
|
*/
|
||||||
|
private List<MimeType> excludedMimeTypes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comma-separated list of user agents to exclude from compression. String.contains is
|
* Comma-separated list of user agents to exclude from compression. String.contains is
|
||||||
* used to determine a match against the request's User-Agent header.
|
* used to determine a match against the request's User-Agent header.
|
||||||
|
|
@ -77,19 +83,19 @@ public class GzipFilterProperties {
|
||||||
* Comma-separated list of regular expression patterns to control user agents excluded
|
* Comma-separated list of regular expression patterns to control user agents excluded
|
||||||
* from compression.
|
* from compression.
|
||||||
*/
|
*/
|
||||||
private String excludedAgentPatterns;
|
private String excludeAgentPatterns;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comma-separated list of paths to exclude from compression. Uses String.startsWith
|
* Comma-separated list of paths to exclude from compression. Uses String.startsWith
|
||||||
* to determine a match against the request's path.
|
* to determine a match against the request's path.
|
||||||
*/
|
*/
|
||||||
private String excludedPaths;
|
private String excludePaths;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comma-separated list of regular expression patterns to control the paths that are
|
* Comma-separated list of regular expression patterns to control the paths that are
|
||||||
* excluded from compression.
|
* excluded from compression.
|
||||||
*/
|
*/
|
||||||
private String excludedPathPatterns;
|
private String excludePathPatterns;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vary header sent on responses that may be compressed.
|
* Vary header sent on responses that may be compressed.
|
||||||
|
|
@ -156,6 +162,16 @@ public class GzipFilterProperties {
|
||||||
this.mimeTypes = mimeTypes;
|
this.mimeTypes = mimeTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<MimeType> getExcludedMimeTypes() {
|
||||||
|
return excludedMimeTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExcludedMimeTypes(List<MimeType> excludedMimeTypes) {
|
||||||
|
this.addInitParameter("excludedMimeTypes",
|
||||||
|
StringUtils.collectionToCommaDelimitedString(excludedMimeTypes));
|
||||||
|
this.excludedMimeTypes = excludedMimeTypes;
|
||||||
|
}
|
||||||
|
|
||||||
public String getExcludedAgents() {
|
public String getExcludedAgents() {
|
||||||
return this.excludedAgents;
|
return this.excludedAgents;
|
||||||
}
|
}
|
||||||
|
|
@ -165,31 +181,31 @@ public class GzipFilterProperties {
|
||||||
this.excludedAgents = excludedAgents;
|
this.excludedAgents = excludedAgents;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getExcludedAgentPatterns() {
|
public String getExcludeAgentPatterns() {
|
||||||
return this.excludedAgentPatterns;
|
return this.excludeAgentPatterns;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setExcludedAgentPatterns(String excludedAgentPatterns) {
|
public void setExcludeAgentPatterns(String excludeAgentPatterns) {
|
||||||
this.addInitParameter("excludedAgentPatterns", excludedAgentPatterns);
|
this.addInitParameter("excludeAgentPatterns", excludeAgentPatterns);
|
||||||
this.excludedAgentPatterns = excludedAgentPatterns;
|
this.excludeAgentPatterns = excludeAgentPatterns;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getExcludedPaths() {
|
public String getExcludePaths() {
|
||||||
return this.excludedPaths;
|
return this.excludePaths;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setExcludedPaths(String excludedPaths) {
|
public void setExcludePaths(String excludePaths) {
|
||||||
this.addInitParameter("excludedPaths", excludedPaths);
|
this.addInitParameter("excludePaths", excludePaths);
|
||||||
this.excludedPaths = excludedPaths;
|
this.excludePaths = excludePaths;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getExcludedPathPatterns() {
|
public String getExcludePathPatterns() {
|
||||||
return this.excludedPathPatterns;
|
return this.excludePathPatterns;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setExcludedPathPatterns(String excludedPathPatterns) {
|
public void setExcludePathPatterns(String excludePathPatterns) {
|
||||||
this.addInitParameter("excludedPathPatterns", excludedPathPatterns);
|
this.addInitParameter("excludePathPatterns", excludePathPatterns);
|
||||||
this.excludedPathPatterns = excludedPathPatterns;
|
this.excludePathPatterns = excludePathPatterns;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getVary() {
|
public String getVary() {
|
||||||
|
|
|
||||||
|
|
@ -69,14 +69,15 @@ public class GzipFilterAutoConfigurationTests {
|
||||||
"spring.http.gzip.deflateNoWrap:false",
|
"spring.http.gzip.deflateNoWrap:false",
|
||||||
"spring.http.gzip.methods:GET,POST",
|
"spring.http.gzip.methods:GET,POST",
|
||||||
"spring.http.gzip.mimeTypes:application/foo,application/bar",
|
"spring.http.gzip.mimeTypes:application/foo,application/bar",
|
||||||
|
"spring.http.gzip.excludedMimeTypes:application/biz",
|
||||||
"spring.http.gzip.excludedAgents:excluded-agent-1,excluded-agent-2",
|
"spring.http.gzip.excludedAgents:excluded-agent-1,excluded-agent-2",
|
||||||
"spring.http.gzip.excludedAgentPatterns:agent-pattern-1,agent-pattern-2",
|
"spring.http.gzip.excludeAgentPatterns:agent-pattern-1,agent-pattern-2",
|
||||||
"spring.http.gzip.excludedPaths:/static/",
|
"spring.http.gzip.excludePaths:/static/",
|
||||||
"spring.http.gzip.excludedPathPatterns:path-pattern",
|
"spring.http.gzip.excludePathPatterns:path-pattern",
|
||||||
"spring.http.gzip.vary:vary-header-value");
|
"spring.http.gzip.vary:vary-header-value");
|
||||||
FilterRegistrationBean registrationBean = this.context.getBean("gzipFilter",
|
FilterRegistrationBean registrationBean = this.context.getBean("gzipFilter",
|
||||||
FilterRegistrationBean.class);
|
FilterRegistrationBean.class);
|
||||||
assertThat(registrationBean.getInitParameters().size(), equalTo(12));
|
assertThat(registrationBean.getInitParameters().size(), equalTo(13));
|
||||||
assertThat(registrationBean.getInitParameters().get("checkGzExists"),
|
assertThat(registrationBean.getInitParameters().get("checkGzExists"),
|
||||||
equalTo("false"));
|
equalTo("false"));
|
||||||
assertThat(registrationBean.getInitParameters().get("bufferSize"),
|
assertThat(registrationBean.getInitParameters().get("bufferSize"),
|
||||||
|
|
@ -91,13 +92,15 @@ public class GzipFilterAutoConfigurationTests {
|
||||||
equalTo("GET,POST"));
|
equalTo("GET,POST"));
|
||||||
assertThat(registrationBean.getInitParameters().get("mimeTypes"),
|
assertThat(registrationBean.getInitParameters().get("mimeTypes"),
|
||||||
equalTo("application/foo,application/bar"));
|
equalTo("application/foo,application/bar"));
|
||||||
|
assertThat(registrationBean.getInitParameters().get("excludedMimeTypes"),
|
||||||
|
equalTo("application/biz"));
|
||||||
assertThat(registrationBean.getInitParameters().get("excludedAgents"),
|
assertThat(registrationBean.getInitParameters().get("excludedAgents"),
|
||||||
equalTo("excluded-agent-1,excluded-agent-2"));
|
equalTo("excluded-agent-1,excluded-agent-2"));
|
||||||
assertThat(registrationBean.getInitParameters().get("excludedAgentPatterns"),
|
assertThat(registrationBean.getInitParameters().get("excludeAgentPatterns"),
|
||||||
equalTo("agent-pattern-1,agent-pattern-2"));
|
equalTo("agent-pattern-1,agent-pattern-2"));
|
||||||
assertThat(registrationBean.getInitParameters().get("excludedPaths"),
|
assertThat(registrationBean.getInitParameters().get("excludePaths"),
|
||||||
equalTo("/static/"));
|
equalTo("/static/"));
|
||||||
assertThat(registrationBean.getInitParameters().get("excludedPathPatterns"),
|
assertThat(registrationBean.getInitParameters().get("excludePathPatterns"),
|
||||||
equalTo("path-pattern"));
|
equalTo("path-pattern"));
|
||||||
assertThat(registrationBean.getInitParameters().get("vary"),
|
assertThat(registrationBean.getInitParameters().get("vary"),
|
||||||
equalTo("vary-header-value"));
|
equalTo("vary-header-value"));
|
||||||
|
|
|
||||||
|
|
@ -126,11 +126,12 @@ content into your application; rather pick only the properties that you need.
|
||||||
spring.http.gzip.deflate-no-wrap= # noWrap setting for deflate compression (true or false)
|
spring.http.gzip.deflate-no-wrap= # noWrap setting for deflate compression (true or false)
|
||||||
spring.http.gzip.enabled=true # enable gzip filter support
|
spring.http.gzip.enabled=true # enable gzip filter support
|
||||||
spring.http.gzip.excluded-agents= # comma-separated list of user agents to exclude from compression
|
spring.http.gzip.excluded-agents= # comma-separated list of user agents to exclude from compression
|
||||||
spring.http.gzip.excluded-agent-patterns= # comma-separated list of regular expression patterns to control user agents excluded from compression
|
spring.http.gzip.exclude-agent-patterns= # comma-separated list of regular expression patterns to control user agents excluded from compression
|
||||||
spring.http.gzip.excluded-paths= # comma-separated list of paths to exclude from compression
|
spring.http.gzip.exclude-paths= # comma-separated list of paths to exclude from compression
|
||||||
spring.http.gzip.excluded-path-patterns= # comma-separated list of regular expression patterns to control the paths that are excluded from compression
|
spring.http.gzip.exclude-path-patterns= # 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.methods= # comma-separated list of HTTP methods for which compression is enabled
|
||||||
spring.http.gzip.mime-types= # comma-separated list of MIME types which should be compressed
|
spring.http.gzip.mime-types= # comma-separated list of MIME types which should be compressed
|
||||||
|
spring.http.gzip.excluded-mime-types= # comma-separated list of MIME types to exclude from compression
|
||||||
spring.http.gzip.min-gzip-size= # minimum content length required for compression to occur
|
spring.http.gzip.min-gzip-size= # minimum content length required for compression to occur
|
||||||
spring.http.gzip.vary= # Vary header to be sent on responses that may be compressed
|
spring.http.gzip.vary= # Vary header to be sent on responses that may be compressed
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue