sdk/dotnet/src/Microsoft.Datasync.Client/Http/ServiceHttpClient.cs
/// <summary>
/// Transform a list of <see cref="HttpMessageHandler"/> objects into a chain suitable for using
/// as the pipeline of a <see cref="HttpClient"/>.
/// </summary>
/// <param name="handlers">The list of <see cref="HttpMessageHandler"/> objects to transform</param>
/// <returns>The chained <see cref="HttpMessageHandler"/></returns>
Transform a list of  objects into a chain suitable for using
as the pipeline of a .
Transform a list of objects into a chain suitable for using as the pipeline of a .
protected HttpMessageHandler CreatePipeline(IEnumerable<HttpMessageHandler> handlers)
        {
            HttpMessageHandler pipeline = handlers.LastOrDefault() ?? DefaultHandlerFactory();
            if (pipeline is DelegatingHandler lastPolicy && lastPolicy.InnerHandler == null)
            {
                lastPolicy.InnerHandler = DefaultHandlerFactory();
                pipeline = lastPolicy;
            }
            foreach (HttpMessageHandler handler in handlers.Reverse().Skip(1))
            {
                if (handler is DelegatingHandler policy)
                {
                    policy.InnerHandler = pipeline;
                    pipeline = policy;
                }
                else
                {
                    throw new ArgumentException("All message handlers except the last one must be 'DelegatingHandler'", nameof(handlers));
                }
            }
            return pipeline;
        }
protected HttpMessageHandler CreatePipeline ( IEnumerable < HttpMessageHandler > handlers ) { HttpMessageHandler pipeline = handlers . LastOrDefault ( ) ?? DefaultHandlerFactory ( ) ; if ( pipeline is DelegatingHandler lastPolicy && lastPolicy . InnerHandler == null ) { lastPolicy . InnerHandler = DefaultHandlerFactory ( ) ; pipeline = lastPolicy ; } foreach ( HttpMessageHandler handler in handlers . Reverse ( ) . Skip ( 1 ) ) { if ( handler is DelegatingHandler policy ) { policy . InnerHandler = pipeline ; pipeline = policy ; } else { throw new ArgumentException ( " " , nameof ( handlers ) ) ; } } return pipeline ; }
Transform a list of  objects into a chain suitable for using
as the pipeline of a .
Transform a list of objects into a chain suitable for using as the pipeline of a .
// Wire handlers up in reverse order
None
handlers
IEnumerable<HttpMessageHandler>
The list of  objects to transform
The list of objects to transform