Search in sources :

Example 1 with Http2

use of org.springframework.boot.web.server.Http2 in project spring-boot by spring-projects.

the class SslServerCustomizerTests method alpnConnectionFactoryHasNullDefaultProtocolToAllowNegotiationToHttp11.

@Test
void alpnConnectionFactoryHasNullDefaultProtocolToAllowNegotiationToHttp11() {
    Http2 http2 = new Http2();
    http2.setEnabled(true);
    Server server = createCustomizedServer(http2);
    assertThat(server.getConnectors()).hasSize(1);
    List<ConnectionFactory> factories = new ArrayList<>(server.getConnectors()[0].getConnectionFactories());
    assertThat(((ALPNServerConnectionFactory) factories.get(1)).getDefaultProtocol()).isNull();
}
Also used : HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) ALPNServerConnectionFactory(org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory) ConnectionFactory(org.eclipse.jetty.server.ConnectionFactory) HTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory) Server(org.eclipse.jetty.server.Server) ALPNServerConnectionFactory(org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory) Http2(org.springframework.boot.web.server.Http2) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 2 with Http2

use of org.springframework.boot.web.server.Http2 in project spring-boot by spring-projects.

the class AbstractServletWebServerFactoryTests method whenHttp2IsEnabledAndSslIsDisabledThenHttp11CanStillBeUsed.

@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");
}
Also used : Http2(org.springframework.boot.web.server.Http2) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 3 with Http2

use of org.springframework.boot.web.server.Http2 in project spring-boot by spring-projects.

the class AbstractReactiveWebServerFactoryTests method whenHttp2IsEnabledAndSslIsDisabledThenH2cCanBeUsed.

@Test
protected void whenHttp2IsEnabledAndSslIsDisabledThenH2cCanBeUsed() throws Exception {
    AbstractReactiveWebServerFactory factory = getFactory();
    Http2 http2 = new Http2();
    http2.setEnabled(true);
    factory.setHttp2(http2);
    this.webServer = factory.getWebServer(new EchoHandler());
    this.webServer.start();
    org.eclipse.jetty.client.HttpClient client = new org.eclipse.jetty.client.HttpClient(new HttpClientTransportOverHTTP2(new HTTP2Client()));
    client.start();
    try {
        ContentResponse response = client.POST("http://localhost:" + this.webServer.getPort()).body(new StringRequestContent("text/plain", "Hello World")).send();
        assertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value());
        assertThat(response.getContentAsString()).isEqualTo("Hello World");
    } finally {
        client.stop();
    }
}
Also used : ContentResponse(org.eclipse.jetty.client.api.ContentResponse) Http2(org.springframework.boot.web.server.Http2) HttpClientTransportOverHTTP2(org.eclipse.jetty.http2.client.http.HttpClientTransportOverHTTP2) HttpClient(reactor.netty.http.client.HttpClient) HTTP2Client(org.eclipse.jetty.http2.client.HTTP2Client) StringRequestContent(org.eclipse.jetty.client.util.StringRequestContent) Test(org.junit.jupiter.api.Test)

Example 4 with Http2

use of org.springframework.boot.web.server.Http2 in project spring-boot by spring-projects.

the class UndertowWebServerFactoryDelegate method createBuilder.

Builder createBuilder(AbstractConfigurableWebServerFactory factory) {
    Ssl ssl = factory.getSsl();
    InetAddress address = factory.getAddress();
    int port = factory.getPort();
    Builder builder = Undertow.builder();
    if (this.bufferSize != null) {
        builder.setBufferSize(this.bufferSize);
    }
    if (this.ioThreads != null) {
        builder.setIoThreads(this.ioThreads);
    }
    if (this.workerThreads != null) {
        builder.setWorkerThreads(this.workerThreads);
    }
    if (this.directBuffers != null) {
        builder.setDirectBuffers(this.directBuffers);
    }
    Http2 http2 = factory.getHttp2();
    if (http2 != null) {
        builder.setServerOption(UndertowOptions.ENABLE_HTTP2, http2.isEnabled());
    }
    if (ssl != null && ssl.isEnabled()) {
        new SslBuilderCustomizer(factory.getPort(), address, ssl, factory.getSslStoreProvider()).customize(builder);
    } else {
        builder.addHttpListener(port, (address != null) ? address.getHostAddress() : "0.0.0.0");
    }
    builder.setServerOption(UndertowOptions.SHUTDOWN_TIMEOUT, 0);
    for (UndertowBuilderCustomizer customizer : this.builderCustomizers) {
        customizer.customize(builder);
    }
    return builder;
}
Also used : Builder(io.undertow.Undertow.Builder) Http2(org.springframework.boot.web.server.Http2) Ssl(org.springframework.boot.web.server.Ssl) InetAddress(java.net.InetAddress)

Example 5 with Http2

use of org.springframework.boot.web.server.Http2 in project spring-boot by spring-projects.

the class AbstractServletWebServerFactoryTests method whenHttp2IsEnabledAndSslIsDisabledThenH2cCanBeUsed.

@Test
protected void whenHttp2IsEnabledAndSslIsDisabledThenH2cCanBeUsed() throws Exception {
    AbstractServletWebServerFactory factory = getFactory();
    Http2 http2 = new Http2();
    http2.setEnabled(true);
    factory.setHttp2(http2);
    this.webServer = factory.getWebServer(exampleServletRegistration());
    this.webServer.start();
    org.eclipse.jetty.client.HttpClient client = new org.eclipse.jetty.client.HttpClient(new HttpClientTransportOverHTTP2(new HTTP2Client()));
    client.start();
    try {
        ContentResponse response = client.GET("http://localhost:" + this.webServer.getPort() + "/hello");
        assertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value());
        assertThat(response.getContentAsString()).isEqualTo("Hello World");
    } finally {
        client.stop();
    }
}
Also used : HttpClientTransportOverHTTP2(org.eclipse.jetty.http2.client.http.HttpClientTransportOverHTTP2) ContentResponse(org.eclipse.jetty.client.api.ContentResponse) Http2(org.springframework.boot.web.server.Http2) HttpClient(org.apache.http.client.HttpClient) HTTP2Client(org.eclipse.jetty.http2.client.HTTP2Client) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Aggregations

Http2 (org.springframework.boot.web.server.Http2)7 Test (org.junit.jupiter.api.Test)6 ArrayList (java.util.ArrayList)2 ALPNServerConnectionFactory (org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory)2 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)2 HTTP2Client (org.eclipse.jetty.http2.client.HTTP2Client)2 HttpClientTransportOverHTTP2 (org.eclipse.jetty.http2.client.http.HttpClientTransportOverHTTP2)2 HTTP2ServerConnectionFactory (org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory)2 ConnectionFactory (org.eclipse.jetty.server.ConnectionFactory)2 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)2 Server (org.eclipse.jetty.server.Server)2 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 Ssl (org.springframework.boot.web.server.Ssl)2 Builder (io.undertow.Undertow.Builder)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1 List (java.util.List)1 HttpClient (org.apache.http.client.HttpClient)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1