mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Configure HTTP compression for HTTP/2 with Tomcat
This commit ensures that the compression options are also applied on the `Http2Protocol` when http/2 is enabled with Tomcat. Closes gh-15591
This commit is contained in:
parent
7330b8b16f
commit
0e13fd039d
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -18,7 +18,9 @@ package org.springframework.boot.web.embedded.tomcat;
|
||||
|
||||
import org.apache.catalina.connector.Connector;
|
||||
import org.apache.coyote.ProtocolHandler;
|
||||
import org.apache.coyote.UpgradeProtocol;
|
||||
import org.apache.coyote.http11.AbstractHttp11Protocol;
|
||||
import org.apache.coyote.http2.Http2Protocol;
|
||||
|
||||
import org.springframework.boot.web.server.Compression;
|
||||
import org.springframework.util.StringUtils;
|
||||
@ -44,6 +46,24 @@ class CompressionConnectorCustomizer implements TomcatConnectorCustomizer {
|
||||
if (handler instanceof AbstractHttp11Protocol) {
|
||||
customize((AbstractHttp11Protocol<?>) handler);
|
||||
}
|
||||
for (UpgradeProtocol upgradeProtocol : connector.findUpgradeProtocols()) {
|
||||
if (upgradeProtocol instanceof Http2Protocol) {
|
||||
customize((Http2Protocol) upgradeProtocol);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void customize(Http2Protocol upgradeProtocol) {
|
||||
Compression compression = this.compression;
|
||||
upgradeProtocol.setCompression("on");
|
||||
upgradeProtocol.setCompressionMinSize(compression.getMinResponseSize());
|
||||
upgradeProtocol.setCompressibleMimeType(
|
||||
StringUtils.arrayToCommaDelimitedString(compression.getMimeTypes()));
|
||||
if (this.compression.getExcludedUserAgents() != null) {
|
||||
upgradeProtocol
|
||||
.setNoCompressionUserAgents(StringUtils.arrayToCommaDelimitedString(
|
||||
this.compression.getExcludedUserAgents()));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user