Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import misk.client.HttpClientConfigUrlProvider
import misk.client.HttpClientFactory
import misk.client.HttpClientsConfig
import misk.moshi.adapter
import okhttp3.Protocol

@Singleton
class GrpcCallbackConnectorProvider @Inject constructor(
Expand Down Expand Up @@ -49,16 +50,22 @@ class GrpcCallbackConnectorProvider @Inject constructor(
val headers: List<HttpHeader>? = extraData!!.headers

val httpClientEndpointConfig = httpClientsConfig[url]
var okHttpClient = httpClientFactory.create(httpClientEndpointConfig)
val baseUrl = httpClientConfigUrlProvider.getUrl(httpClientEndpointConfig)

val okHttpClientBuilder = httpClientFactory.create(httpClientEndpointConfig).newBuilder()
if (!headers.isNullOrEmpty()) {
okHttpClient = okHttpClient.newBuilder()
.addInterceptor(OkHttpClientSpecifiedHeadersInterceptor(headers))
.build()
okHttpClientBuilder.addInterceptor(OkHttpClientSpecifiedHeadersInterceptor(headers))
}

// Since gRPC uses HTTP/2, force h2c when calling an unencrypted endpoint
if (baseUrl.startsWith("http://")) {
okHttpClientBuilder.protocols(listOf(Protocol.H2_PRIOR_KNOWLEDGE))
} else {
okHttpClientBuilder.protocols(listOf(Protocol.HTTP_2, Protocol.HTTP_1_1))
}

val baseUrl = httpClientConfigUrlProvider.getUrl(httpClientEndpointConfig)
val grpcClient = GrpcClient.Builder()
.client(okHttpClient)
.client(okHttpClientBuilder.build())
.baseUrl(baseUrl)
.build()
val api = grpcClient.create(BackfilaClientServiceClient::class)
Expand Down
Loading