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.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
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.AbstractConnector;
|
||||||
import org.eclipse.jetty.server.ConnectionFactory;
|
import org.eclipse.jetty.server.ConnectionFactory;
|
||||||
import org.eclipse.jetty.server.Handler;
|
import org.eclipse.jetty.server.Handler;
|
||||||
|
@ -199,10 +199,10 @@ public class JettyReactiveWebServerFactory extends AbstractReactiveWebServerFact
|
||||||
HttpConfiguration httpConfiguration = new HttpConfiguration();
|
HttpConfiguration httpConfiguration = new HttpConfiguration();
|
||||||
httpConfiguration.setSendServerVersion(false);
|
httpConfiguration.setSendServerVersion(false);
|
||||||
List<ConnectionFactory> connectionFactories = new ArrayList<>();
|
List<ConnectionFactory> connectionFactories = new ArrayList<>();
|
||||||
if (getHttp2() != null && getHttp2().isEnabled()) {
|
|
||||||
connectionFactories.add(new HTTP2ServerConnectionFactory(httpConfiguration));
|
|
||||||
}
|
|
||||||
connectionFactories.add(new HttpConnectionFactory(httpConfiguration));
|
connectionFactories.add(new HttpConnectionFactory(httpConfiguration));
|
||||||
|
if (getHttp2() != null && getHttp2().isEnabled()) {
|
||||||
|
connectionFactories.add(new HTTP2CServerConnectionFactory(httpConfiguration));
|
||||||
|
}
|
||||||
JettyResourceFactory resourceFactory = getResourceFactory();
|
JettyResourceFactory resourceFactory = getResourceFactory();
|
||||||
ServerConnector connector;
|
ServerConnector connector;
|
||||||
if (resourceFactory != null) {
|
if (resourceFactory != null) {
|
||||||
|
|
|
@ -34,7 +34,7 @@ import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.eclipse.jetty.http.MimeTypes;
|
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.AbstractConnector;
|
||||||
import org.eclipse.jetty.server.ConnectionFactory;
|
import org.eclipse.jetty.server.ConnectionFactory;
|
||||||
import org.eclipse.jetty.server.Connector;
|
import org.eclipse.jetty.server.Connector;
|
||||||
|
@ -180,10 +180,10 @@ public class JettyServletWebServerFactory extends AbstractServletWebServerFactor
|
||||||
HttpConfiguration httpConfiguration = new HttpConfiguration();
|
HttpConfiguration httpConfiguration = new HttpConfiguration();
|
||||||
httpConfiguration.setSendServerVersion(false);
|
httpConfiguration.setSendServerVersion(false);
|
||||||
List<ConnectionFactory> connectionFactories = new ArrayList<>();
|
List<ConnectionFactory> connectionFactories = new ArrayList<>();
|
||||||
if (getHttp2() != null && getHttp2().isEnabled()) {
|
|
||||||
connectionFactories.add(new HTTP2ServerConnectionFactory(httpConfiguration));
|
|
||||||
}
|
|
||||||
connectionFactories.add(new HttpConnectionFactory(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,
|
ServerConnector connector = new ServerConnector(server, this.acceptors, this.selectors,
|
||||||
connectionFactories.toArray(new ConnectionFactory[0]));
|
connectionFactories.toArray(new ConnectionFactory[0]));
|
||||||
connector.setHost(address.getHostString());
|
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() {
|
protected WebClient prepareCompressionTest() {
|
||||||
Compression compression = new Compression();
|
Compression compression = new Compression();
|
||||||
compression.setEnabled(true);
|
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) {
|
protected Future<Object> initiateGetRequest(int port, String path) {
|
||||||
return initiateGetRequest(HttpClients.createMinimal(), port, path);
|
return initiateGetRequest(HttpClients.createMinimal(), port, path);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue