示例#1
0
        public HttpMessageHandler CreateHandler(HttpClientOptions options)
        {
            Check.NotNull(options, nameof(options));
            var entry = _activeHandlers.GetOrAdd(options.Name, k => _entryFactory(options)).Value;

            StartHandlerEntryTimer(entry);
            return(entry.Handler);
        }
        public HttpClient CreateClient(HttpClientOptions options)
        {
            Check.NotNull(options, nameof(options));
            var handler = _httpMessageHandlerFactory.CreateHandler(options);
            var client  = new HttpClient(handler, disposeHandler: false);

            return(client);
        }
示例#3
0
        private ActiveHandlerTrackingEntry CreateHandlerEntry(HttpClientOptions options)
        {
            var builder = new DefaultHttpMessageHandlerBuilder(options.Proxy);

            foreach (var action in options.HttpMessageHandlerBuilderActions)
            {
                action(builder);
            }
            var handler = new LifetimeTrackingHttpMessageHandler(builder.Build());

            // Note that we can't start the timer here. That would introduce a very very subtle race condition
            // with very short expiry times. We need to wait until we've actually handed out the handler once
            // to start the timer.
            //
            // Otherwise it would be possible that we start the timer here, immediately expire it (very short
            // timer) and then dispose it without ever creating a client. That would be bad. It's unlikely
            // this would happen, but we want to be sure.
            return(new ActiveHandlerTrackingEntry(options.Name, handler, options.HandlerLifetime));
        }