Test that HTTP/1.1 still works when HTTP/2 is enabled
See gh-25856
This commit is contained in:
parent
74b91b78fe
commit
252d4e98c5
|
@ -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<ConnectionFactory> connectionFactories = new ArrayList<>();
|
||||
if (getHttp2() != null && getHttp2().isEnabled()) {
|
||||
connectionFactories.add(new HTTP2ServerConnectionFactory(httpConfiguration));
|
||||
}
|
||||
connectionFactories.add(new HttpConnectionFactory(httpConfiguration));
|
||||
if (getHttp2() != null && getHttp2().isEnabled()) {
|
||||
connectionFactories.add(new HTTP2CServerConnectionFactory(httpConfiguration));
|
||||
}
|
||||
JettyResourceFactory resourceFactory = getResourceFactory();
|
||||
ServerConnector connector;
|
||||
if (resourceFactory != null) {
|
||||
|
|
|
@ -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<ConnectionFactory> connectionFactories = new ArrayList<>();
|
||||
if (getHttp2() != null && getHttp2().isEnabled()) {
|
||||
connectionFactories.add(new HTTP2ServerConnectionFactory(httpConfiguration));
|
||||
}
|
||||
connectionFactories.add(new HttpConnectionFactory(httpConfiguration));
|
||||
if (getHttp2() != null && getHttp2().isEnabled()) {
|
||||
connectionFactories.add(new HTTP2CServerConnectionFactory(httpConfiguration));
|
||||
}
|
||||
ServerConnector connector = new ServerConnector(server, this.acceptors, this.selectors,
|
||||
connectionFactories.toArray(new ConnectionFactory[0]));
|
||||
connector.setHost(address.getHostString());
|
||||
|
|
|
@ -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<String> 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);
|
||||
|
|
|
@ -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<Object> initiateGetRequest(int port, String path) {
|
||||
return initiateGetRequest(HttpClients.createMinimal(), port, path);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue