@@ -12,6 +12,7 @@ import misk.client.HttpClientConfigUrlProvider
12
12
import misk.client.HttpClientFactory
13
13
import misk.client.HttpClientsConfig
14
14
import misk.moshi.adapter
15
+ import okhttp3.Protocol
15
16
16
17
@Singleton
17
18
class GrpcCallbackConnectorProvider @Inject constructor(
@@ -49,16 +50,22 @@ class GrpcCallbackConnectorProvider @Inject constructor(
49
50
val headers: List <HttpHeader >? = extraData!! .headers
50
51
51
52
val httpClientEndpointConfig = httpClientsConfig[url]
52
- var okHttpClient = httpClientFactory.create(httpClientEndpointConfig)
53
+ val baseUrl = httpClientConfigUrlProvider.getUrl(httpClientEndpointConfig)
54
+
55
+ val okHttpClientBuilder = httpClientFactory.create(httpClientEndpointConfig).newBuilder()
53
56
if (! headers.isNullOrEmpty()) {
54
- okHttpClient = okHttpClient.newBuilder()
55
- .addInterceptor(OkHttpClientSpecifiedHeadersInterceptor (headers))
56
- .build()
57
+ okHttpClientBuilder.addInterceptor(OkHttpClientSpecifiedHeadersInterceptor (headers))
58
+ }
59
+
60
+ // Since gRPC uses HTTP/2, force h2c when calling an unencrypted endpoint
61
+ if (baseUrl.startsWith(" http://" )) {
62
+ okHttpClientBuilder.protocols(listOf (Protocol .H2_PRIOR_KNOWLEDGE ))
63
+ } else {
64
+ okHttpClientBuilder.protocols(listOf (Protocol .HTTP_2 , Protocol .HTTP_1_1 ))
57
65
}
58
66
59
- val baseUrl = httpClientConfigUrlProvider.getUrl(httpClientEndpointConfig)
60
67
val grpcClient = GrpcClient .Builder ()
61
- .client(okHttpClient )
68
+ .client(okHttpClientBuilder.build() )
62
69
.baseUrl(baseUrl)
63
70
.build()
64
71
val api = grpcClient.create(BackfilaClientServiceClient ::class )
0 commit comments