1717package io .grpc .okhttp ;
1818
1919import static com .google .common .base .Preconditions .checkNotNull ;
20+ import static io .grpc .internal .CertificateUtils .createTrustManager ;
2021import static io .grpc .internal .GrpcUtil .DEFAULT_KEEPALIVE_TIMEOUT_NANOS ;
2122import static io .grpc .internal .GrpcUtil .KEEPALIVE_TIME_NANOS_DISABLED ;
2223
@@ -89,6 +90,7 @@ public final class OkHttpChannelBuilder extends ForwardingChannelBuilder2<OkHttp
8990 public static final int DEFAULT_FLOW_CONTROL_WINDOW = 65535 ;
9091
9192 private final ManagedChannelImplBuilder managedChannelImplBuilder ;
93+ private final ChannelCredentials channelCredentials ;
9294 private TransportTracer .Factory transportTracerFactory = TransportTracer .getDefaultFactory ();
9395
9496
@@ -206,6 +208,7 @@ private OkHttpChannelBuilder(String target) {
206208 new OkHttpChannelTransportFactoryBuilder (),
207209 new OkHttpChannelDefaultPortProvider ());
208210 this .freezeSecurityConfiguration = false ;
211+ this .channelCredentials = null ;
209212 }
210213
211214 OkHttpChannelBuilder (
@@ -218,6 +221,7 @@ private OkHttpChannelBuilder(String target) {
218221 this .sslSocketFactory = factory ;
219222 this .negotiationType = factory == null ? NegotiationType .PLAINTEXT : NegotiationType .TLS ;
220223 this .freezeSecurityConfiguration = true ;
224+ this .channelCredentials = channelCreds ;
221225 }
222226
223227 private final class OkHttpChannelTransportFactoryBuilder
@@ -534,7 +538,8 @@ OkHttpTransportFactory buildTransportFactory() {
534538 keepAliveWithoutCalls ,
535539 maxInboundMetadataSize ,
536540 transportTracerFactory ,
537- useGetForSafeMethods );
541+ useGetForSafeMethods ,
542+ channelCredentials );
538543 }
539544
540545 OkHttpChannelBuilder disableCheckAuthority () {
@@ -777,6 +782,7 @@ static final class OkHttpTransportFactory implements ClientTransportFactory {
777782 private final boolean keepAliveWithoutCalls ;
778783 final int maxInboundMetadataSize ;
779784 final boolean useGetForSafeMethods ;
785+ private final ChannelCredentials channelCredentials ;
780786 private boolean closed ;
781787
782788 private OkHttpTransportFactory (
@@ -794,7 +800,8 @@ private OkHttpTransportFactory(
794800 boolean keepAliveWithoutCalls ,
795801 int maxInboundMetadataSize ,
796802 TransportTracer .Factory transportTracerFactory ,
797- boolean useGetForSafeMethods ) {
803+ boolean useGetForSafeMethods ,
804+ ChannelCredentials channelCredentials ) {
798805 this .executorPool = executorPool ;
799806 this .executor = executorPool .getObject ();
800807 this .scheduledExecutorServicePool = scheduledExecutorServicePool ;
@@ -812,6 +819,7 @@ private OkHttpTransportFactory(
812819 this .keepAliveWithoutCalls = keepAliveWithoutCalls ;
813820 this .maxInboundMetadataSize = maxInboundMetadataSize ;
814821 this .useGetForSafeMethods = useGetForSafeMethods ;
822+ this .channelCredentials = channelCredentials ;
815823
816824 this .transportTracerFactory =
817825 Preconditions .checkNotNull (transportTracerFactory , "transportTracerFactory" );
@@ -839,7 +847,8 @@ public void run() {
839847 options .getUserAgent (),
840848 options .getEagAttributes (),
841849 options .getHttpConnectProxiedSocketAddress (),
842- tooManyPingsRunnable );
850+ tooManyPingsRunnable ,
851+ channelCredentials );
843852 if (enableKeepAlive ) {
844853 transport .enableKeepAlive (
845854 true , keepAliveTimeNanosState .get (), keepAliveTimeoutNanos , keepAliveWithoutCalls );
@@ -875,7 +884,8 @@ public SwapChannelCredentialsResult swapChannelCredentials(ChannelCredentials ch
875884 keepAliveWithoutCalls ,
876885 maxInboundMetadataSize ,
877886 transportTracerFactory ,
878- useGetForSafeMethods );
887+ useGetForSafeMethods ,
888+ channelCredentials );
879889 return new SwapChannelCredentialsResult (factory , result .callCredentials );
880890 }
881891
0 commit comments