diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/CompressionConnectorCustomizer.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/CompressionConnectorCustomizer.java index 02bd141a9e..c6cdee070e 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/CompressionConnectorCustomizer.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/CompressionConnectorCustomizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 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,25 @@ 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((int) compression.getMinResponseSize().toBytes()); + upgradeProtocol.setCompressibleMimeType( + StringUtils.arrayToCommaDelimitedString(compression.getMimeTypes())); + if (this.compression.getExcludedUserAgents() != null) { + upgradeProtocol + .setNoCompressionUserAgents(StringUtils.arrayToCommaDelimitedString( + this.compression.getExcludedUserAgents())); } }