user1470509
user1470509

Reputation: 111

Feign OKHttpClient with Http2

I set up a basic http2 client with okhttp

http2 is enabled for the URL below.

@FeignClient(name = "client", url = "https://http2.pro/api/v1", configuration = FeignConfig.class)
public interface TestClient {

    @GetMapping("/")
    String callServer();

}
feign.client.config.default.logger-level=full
feign.okhttp.enabled=true
logging.level.com.example=DEBUG
logging.level.okhttp3=DEBUG

When I hit this service in the logs I see HTTP 1.1.

Since I already know this service is using Http2

How can i enforce my client to use HTTP 2 protocol.

om.example.http2clientpoc.TestClient    : [TestClient#callServer] ---> GET https://http2.pro/api/v1/ HTTP/1.1
2023-02-07 12:42:53.704 DEBUG 53855 --- [           main] com.example.http2clientpoc.TestClient    : [TestClient#callServer] ---> END HTTP (0-byte body)
2023-02-07 12:42:54.080 DEBUG 53855 --- [           main] okhttp3.internal.http2.Http2             : >> CONNECTION 505249202a20485454502f322e300d0a0d0a534d0d0a0d0a
2023-02-07 12:42:54.081 DEBUG 53855 --- [           main] okhttp3.internal.http2.Http2             : >> 0x00000000     6 SETTINGS      
2023-02-07 12:42:54.081 DEBUG 53855 --- [           main] okhttp3.internal.http2.Http2             : >> 0x00000000     4 WINDOW_UPDATE 


Prior knowledge is not working (exception message : H2_PRIOR_KNOWLEDGE cannot be used with HTTPS)

 @Bean
    OkHttpClient httpClient() {
       return new OkHttpClient(new okhttp3.OkHttpClient.Builder()
            .protocols(List.of(Protocol.H2_PRIOR_KNOWLEDGE)).build());
    }

Upvotes: 1

Views: 1252

Answers (1)

Jesse Wilson
Jesse Wilson

Reputation: 40585

Try this:

@Bean
OkHttpClient httpClient() {
   return new OkHttpClient(new okhttp3.OkHttpClient.Builder()
        .protocols(List.of(Protocol.H2)).build());
}

Upvotes: 0

Related Questions