diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyReactiveWebServerFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyReactiveWebServerFactory.java index 3913bd9f30..b386bbaab0 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyReactiveWebServerFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyReactiveWebServerFactory.java @@ -26,7 +26,7 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory; +import org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory; import org.eclipse.jetty.server.AbstractConnector; import org.eclipse.jetty.server.ConnectionFactory; import org.eclipse.jetty.server.Handler; @@ -199,10 +199,10 @@ public class JettyReactiveWebServerFactory extends AbstractReactiveWebServerFact HttpConfiguration httpConfiguration = new HttpConfiguration(); httpConfiguration.setSendServerVersion(false); List connectionFactories = new ArrayList<>(); + connectionFactories.add(new HttpConnectionFactory(httpConfiguration)); if (getHttp2() != null && getHttp2().isEnabled()) { - connectionFactories.add(new HTTP2ServerConnectionFactory(httpConfiguration)); + connectionFactories.add(new HTTP2CServerConnectionFactory(httpConfiguration)); } - connectionFactories.add(new HttpConnectionFactory(httpConfiguration)); JettyResourceFactory resourceFactory = getResourceFactory(); ServerConnector connector; if (resourceFactory != null) { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactory.java index 5495d81508..2385cf663d 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactory.java @@ -34,7 +34,7 @@ import java.util.List; import java.util.Set; import org.eclipse.jetty.http.MimeTypes; -import org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory; +import org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory; import org.eclipse.jetty.server.AbstractConnector; import org.eclipse.jetty.server.ConnectionFactory; import org.eclipse.jetty.server.Connector; @@ -180,10 +180,10 @@ public class JettyServletWebServerFactory extends AbstractServletWebServerFactor HttpConfiguration httpConfiguration = new HttpConfiguration(); httpConfiguration.setSendServerVersion(false); List connectionFactories = new ArrayList<>(); + connectionFactories.add(new HttpConnectionFactory(httpConfiguration)); if (getHttp2() != null && getHttp2().isEnabled()) { - connectionFactories.add(new HTTP2ServerConnectionFactory(httpConfiguration)); + connectionFactories.add(new HTTP2CServerConnectionFactory(httpConfiguration)); } - connectionFactories.add(new HttpConnectionFactory(httpConfiguration)); ServerConnector connector = new ServerConnector(server, this.acceptors, this.selectors, connectionFactories.toArray(new ConnectionFactory[0])); connector.setHost(address.getHostString()); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/server/AbstractReactiveWebServerFactoryTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/server/AbstractReactiveWebServerFactoryTests.java index 252fe8c665..69cc7169f6 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/server/AbstractReactiveWebServerFactoryTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/server/AbstractReactiveWebServerFactoryTests.java @@ -491,6 +491,21 @@ public abstract class AbstractReactiveWebServerFactoryTests { } } + @Test + protected void whenHttp2IsEnabledAndSslIsDisabledThenHttp11CanStillBeUsed() + throws InterruptedException, ExecutionException, IOException { + AbstractReactiveWebServerFactory factory = getFactory(); + Http2 http2 = new Http2(); + http2.setEnabled(true); + factory.setHttp2(http2); + this.webServer = factory.getWebServer(new EchoHandler()); + this.webServer.start(); + Mono result = getWebClient(this.webServer.getPort()).build().post().uri("/test") + .contentType(MediaType.TEXT_PLAIN).body(BodyInserters.fromValue("Hello World")).retrieve() + .bodyToMono(String.class); + assertThat(result.block(Duration.ofSeconds(30))).isEqualTo("Hello World"); + } + protected WebClient prepareCompressionTest() { Compression compression = new Compression(); compression.setEnabled(true); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java index e1fead8881..2cba1b5707 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java @@ -1162,6 +1162,18 @@ public abstract class AbstractServletWebServerFactoryTests { } } + @Test + protected void whenHttp2IsEnabledAndSslIsDisabledThenHttp11CanStillBeUsed() + throws InterruptedException, ExecutionException, IOException, URISyntaxException { + AbstractServletWebServerFactory factory = getFactory(); + Http2 http2 = new Http2(); + http2.setEnabled(true); + factory.setHttp2(http2); + this.webServer = factory.getWebServer(exampleServletRegistration()); + this.webServer.start(); + assertThat(getResponse("http://localhost:" + this.webServer.getPort() + "/hello")).isEqualTo("Hello World"); + } + protected Future initiateGetRequest(int port, String path) { return initiateGetRequest(HttpClients.createMinimal(), port, path); }