Skip to content

Commit

Permalink
Merge pull request #34906 from geoand/#34896
Browse files Browse the repository at this point in the history
Allow the use of HTTP2 in programmatically created REST Client
  • Loading branch information
gastaldi authored Jul 21, 2023
2 parents 9e7befa + a43fd01 commit e701cb9
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ public <T> T build(Class<T> aClass) throws IllegalStateException, RestClientDefi

if (getConfiguration().hasProperty(QuarkusRestClientProperties.HTTP2)) {
clientBuilder.http2((Boolean) getConfiguration().getProperty(QuarkusRestClientProperties.HTTP2));
} else if (restClientsConfig.http2) {
clientBuilder.http2(true);
}

Boolean enableCompression = ConfigProvider.getConfig()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.quarkus.it.rest.client.http2;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.core.Response;

@Path("/ping")
public interface Client2 {

@GET
Response ping();
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
package io.quarkus.it.rest.client.http2;

import java.net.MalformedURLException;
import java.net.URL;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.core.Response;

import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipse.microprofile.rest.client.RestClientBuilder;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.jboss.resteasy.reactive.client.impl.ClientResponseImpl;

@Path("")
public class Resource {

@RestClient
Client client;
private final Client client;
private final Client2 client2;

public Resource(@ConfigProperty(name = "test.url") String testUrl, @RestClient Client client) {
this.client = client;
try {
this.client2 = RestClientBuilder.newBuilder()
.baseUrl(new URL(testUrl))
.build(Client2.class);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}

@GET
@Path("/client/ping")
Expand All @@ -24,6 +40,17 @@ public Response client() {
return Response.noContent().build();
}

@GET
@Path("/client2/ping")
public Response client2() {
Response response = client2.ping();
if (((ClientResponseImpl) response).getHttpVersion().equals("HTTP_2")) {
return response;
}

return Response.noContent().build();
}

@GET
@Path("/ping")
public String ping() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ quarkus.rest-client.basic-client.http2=true
quarkus.rest-client.multipart-client.url=${test.url}
quarkus.rest-client.multipart-client.http2=true

quarkus.http.http2=true
#used for the manually created client
quarkus.rest-client.http2=true

quarkus.http.http2=true
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public class ResourceTest {
@TestHTTPResource(value = "/client/ping")
URL clientUrl;

@TestHTTPResource(value = "/client2/ping")
URL client2Url;

private WebClient webClient;

@BeforeEach
Expand Down Expand Up @@ -56,6 +59,13 @@ public void shouldReturnPongFromClient() throws Exception {
assertEquals("pong", response.bodyAsString());
}

@Test
public void shouldReturnPongFromManuallyCreatedClient() throws Exception {
HttpResponse<?> response = call(client2Url);
// if it's empty, it's because the REST Client is not using the HTTP/2 version
assertEquals("pong", response.bodyAsString());
}

private HttpResponse<?> call(URL url) throws Exception {
CompletableFuture<HttpResponse<Buffer>> result = new CompletableFuture<>();
webClient.get(url.getPort(), url.getHost(), url.getPath())
Expand Down

0 comments on commit e701cb9

Please sign in to comment.