internal GrpcChannel(Uri address, GrpcChannelOptions channelOptions) : base(address.Authority) { _methodInfoCache = new ConcurrentDictionary <IMethod, GrpcMethodInfo>(); // Dispose the HTTP client/handler if... // 1. No client/handler was specified and so the channel created the client itself // 2. User has specified a client/handler and set DisposeHttpClient to true _shouldDisposeHttpClient = (channelOptions.HttpClient == null && channelOptions.HttpHandler == null) || channelOptions.DisposeHttpClient; Address = address; HttpInvoker = channelOptions.HttpClient ?? CreateInternalHttpInvoker(channelOptions.HttpHandler); IsWinHttp = channelOptions.HttpHandler != null?HttpHandlerFactory.HasHttpHandlerType(channelOptions.HttpHandler, "System.Net.Http.WinHttpHandler") : false; SendMaxMessageSize = channelOptions.MaxSendMessageSize; ReceiveMaxMessageSize = channelOptions.MaxReceiveMessageSize; CompressionProviders = ResolveCompressionProviders(channelOptions.CompressionProviders); MessageAcceptEncoding = GrpcProtocolHelpers.GetMessageAcceptEncoding(CompressionProviders); LoggerFactory = channelOptions.LoggerFactory ?? NullLoggerFactory.Instance; ThrowOperationCanceledOnCancellation = channelOptions.ThrowOperationCanceledOnCancellation; _createMethodInfoFunc = CreateMethodInfo; ActiveCalls = new HashSet <IDisposable>(); if (channelOptions.Credentials != null) { var configurator = new DefaultChannelCredentialsConfigurator(); channelOptions.Credentials.InternalPopulateConfiguration(configurator, null); IsSecure = configurator.IsSecure; CallCredentials = configurator.CallCredentials; ValidateChannelCredentials(); } }
internal GrpcChannel(Uri address, GrpcChannelOptions channelOptions) : base(address.Authority) { _lock = new object(); _methodInfoCache = new ConcurrentDictionary <IMethod, GrpcMethodInfo>(); // Dispose the HTTP client/handler if... // 1. No client/handler was specified and so the channel created the client itself // 2. User has specified a client/handler and set DisposeHttpClient to true _shouldDisposeHttpClient = (channelOptions.HttpClient == null && channelOptions.HttpHandler == null) || channelOptions.DisposeHttpClient; Address = address; HttpInvoker = channelOptions.HttpClient ?? CreateInternalHttpInvoker(channelOptions.HttpHandler); IsWinHttp = channelOptions.HttpHandler != null?HttpHandlerFactory.HasHttpHandlerType(channelOptions.HttpHandler, "System.Net.Http.WinHttpHandler") : false; SendMaxMessageSize = channelOptions.MaxSendMessageSize; ReceiveMaxMessageSize = channelOptions.MaxReceiveMessageSize; MaxRetryAttempts = channelOptions.MaxRetryAttempts; MaxRetryBufferSize = channelOptions.MaxRetryBufferSize; MaxRetryBufferPerCallSize = channelOptions.MaxRetryBufferPerCallSize; CompressionProviders = ResolveCompressionProviders(channelOptions.CompressionProviders); MessageAcceptEncoding = GrpcProtocolHelpers.GetMessageAcceptEncoding(CompressionProviders); LoggerFactory = channelOptions.LoggerFactory ?? NullLoggerFactory.Instance; Logger = LoggerFactory.CreateLogger <GrpcChannel>(); ThrowOperationCanceledOnCancellation = channelOptions.ThrowOperationCanceledOnCancellation; _createMethodInfoFunc = CreateMethodInfo; ActiveCalls = new HashSet <IDisposable>(); if (channelOptions.ServiceConfig is { } serviceConfig) { RetryThrottling = serviceConfig.RetryThrottling != null?CreateChannelRetryThrottling(serviceConfig.RetryThrottling) : null; _serviceConfigMethods = CreateServiceConfigMethods(serviceConfig); _random = new Random(); } if (channelOptions.Credentials != null) { var configurator = new DefaultChannelCredentialsConfigurator(); channelOptions.Credentials.InternalPopulateConfiguration(configurator, null); IsSecure = configurator.IsSecure; CallCredentials = configurator.CallCredentials; ValidateChannelCredentials(); } if (!string.IsNullOrEmpty(Address.PathAndQuery) && Address.PathAndQuery != "/") { Log.AddressPathUnused(Logger, Address.OriginalString); } }