/// <summary>
        /// Create delegating handler
        /// </summary>
        /// <param name="next"></param>
        /// <param name="resourceId"></param>
        /// <param name="handlers"></param>
        /// <param name="proxy"></param>
        /// <param name="logger"></param>
        public HttpHandlerDelegate(HttpMessageHandler next, string resourceId,
                                   IEnumerable <IHttpHandler> handlers,
                                   IWebProxy proxy, ILogger logger) : base(next)
        {
            _resourceId = resourceId;
            _logger     = logger ?? throw new ArgumentNullException(nameof(logger));

            var root = next.GetRoot();

            if (root == null)
            {
                _logger.Error("Cannot configure root handler, inner " +
                              "most handler is not a configurable client handler");
                return;
            }

            if (proxy != null)
            {
                if (root.SupportsProxy)
                {
                    root.UseProxy = true;
                    root.Proxy    = proxy;
                }
                else
                {
                    _logger.Warning("Proxy configuration provided, but " +
                                    "underlying handler does not support proxy " +
                                    "configuration.  Skipping proxy.");
                }
            }

            if (handlers == null)
            {
                handlers = Enumerable.Empty <IHttpHandler>();
            }

            // Register validators
            var validators = handlers
                             .OfType <IHttpCertificateValidator>()
                             .Cast <IHttpCertificateValidator>()
                             .ToList();

            if (validators.Any())
            {
                validators.ForEach(h => h.Configure(this));
                root.ServerCertificateCustomValidationCallback =
                    (req, cert, chain, err) => validators.All(
                        v => v.Validate(req.Headers, cert, chain, err));
            }

            // Save message handlers
            _handlers = handlers
                        .OfType <IHttpMessageHandler>()
                        .Cast <IHttpMessageHandler>()
                        .OrderBy(h => h.Order)
                        .ToList();
            _handlers.ForEach(h => h.Configure(this));
        }