public static Stream Create(
     Func <long, Stream> responseFactory,
     Func <long, ValueTask <Stream> > asyncResponseFactory,
     ResponseClassifier responseClassifier,
     int maxRetries)
 {
     return(Create(responseFactory(0), responseFactory, asyncResponseFactory, responseClassifier, maxRetries));
 }
 public static async Task <Stream> CreateAsync(
     Func <long, Stream> responseFactory,
     Func <long, ValueTask <Stream> > asyncResponseFactory,
     ResponseClassifier responseClassifier,
     int maxRetries)
 {
     return(Create(await asyncResponseFactory(0).ConfigureAwait(false), responseFactory, asyncResponseFactory, responseClassifier, maxRetries));
 }
 public static Stream Create(
     Response initialResponse,
     Func <long, Response> responseFactory,
     Func <long, Task <Response> > asyncResponseFactory,
     ResponseClassifier responseClassifier,
     int maxRetries)
 {
     return(new RetriableStreamImpl(initialResponse, responseFactory, asyncResponseFactory, responseClassifier, maxRetries));
 }
 public RetriableStreamImpl(Response initialResponse, Func <long, Response> responseFactory, Func <long, Task <Response> > asyncResponseFactory, ResponseClassifier responseClassifier, int maxRetries)
 {
     _initialStream        = EnsureStream(initialResponse);
     _currentStream        = EnsureStream(initialResponse);
     _responseFactory      = responseFactory;
     _responseClassifier   = responseClassifier;
     _asyncResponseFactory = asyncResponseFactory;
     _maxRetries           = maxRetries;
 }
 public static Stream Create(
     Stream initialResponse,
     Func <long, Stream> streamFactory,
     Func <long, ValueTask <Stream> > asyncResponseFactory,
     ResponseClassifier responseClassifier,
     int maxRetries)
 {
     return(new RetriableStreamImpl(initialResponse, streamFactory, asyncResponseFactory, responseClassifier, maxRetries));
 }
 public RetriableStreamImpl(Stream initialStream, Func <long, Stream> streamFactory, Func <long, ValueTask <Stream> > asyncStreamFactory, ResponseClassifier responseClassifier, int maxRetries)
 {
     _initialStream      = EnsureStream(initialStream);
     _currentStream      = EnsureStream(initialStream);
     _streamFactory      = streamFactory;
     _responseClassifier = responseClassifier;
     _asyncStreamFactory = asyncStreamFactory;
     _maxRetries         = maxRetries;
 }
示例#7
0
        public HttpPipeline(HttpPipelineTransport transport, HttpPipelinePolicy[] policies = null, ResponseClassifier responseClassifier = null)
        {
            _transport          = transport ?? throw new ArgumentNullException(nameof(transport));
            _responseClassifier = responseClassifier ?? new ResponseClassifier();

            policies = policies ?? Array.Empty <HttpPipelinePolicy>();

            var all = new HttpPipelinePolicy[policies.Length + 1];

            all[policies.Length] = new HttpPipelineTransportPolicy(_transport);
            policies.CopyTo(all, 0);

            _pipeline = all;
        }
示例#8
0
        public static HttpPipeline Build(HttpClientOptions options, ResponseClassifier responseClassifier, params HttpPipelinePolicy[] clientPolicies)
        {
            var policies = new List <HttpPipelinePolicy>();

            policies.AddRange(options.PerCallPolicies);

            policies.Add(options.TelemetryPolicy);

            policies.AddRange(clientPolicies);

            policies.AddRange(options.PerRetryPolicies);

            policies.RemoveAll(policy => policy == null);

            return(new HttpPipeline(options.Transport, policies.ToArray(), options.ResponseClassifier, options.ServiceProvider));
        }
            public RetriableStreamImpl(Stream initialStream, Func <long, Stream> streamFactory, Func <long, ValueTask <Stream> > asyncStreamFactory, ResponseClassifier responseClassifier, int maxRetries)
            {
                try
                {
                    _length = EnsureStream(initialStream).Length;
                }
                catch (Exception ex)
                {
                    _lengthException = ExceptionDispatchInfo.Capture(ex);
                }

                _currentStream      = EnsureStream(initialStream);
                _streamFactory      = streamFactory;
                _responseClassifier = responseClassifier;
                _asyncStreamFactory = asyncStreamFactory;
                _maxRetries         = maxRetries;
            }
示例#10
0
        internal HttpPipeline(
            HttpPipelineTransport transport,
            int perCallIndex,
            int perRetryIndex,
            HttpPipelinePolicy[] pipeline,
            ResponseClassifier responseClassifier)
        {
            ResponseClassifier = responseClassifier ?? throw new ArgumentNullException(nameof(responseClassifier));

            _transport = transport ?? throw new ArgumentNullException(nameof(transport));
            _pipeline  = pipeline ?? throw new ArgumentNullException(nameof(pipeline));

            Debug.Assert(pipeline[pipeline.Length - 1] is HttpPipelineTransportPolicy);

            _perCallIndex          = perCallIndex;
            _perRetryIndex         = perRetryIndex;
            _internallyConstructed = true;
        }
示例#11
0
        public static HttpPipeline Build(HttpClientOptions options, ResponseClassifier responseClassifier, params HttpPipelinePolicy[] clientPolicies)
        {
            var policies = new List <HttpPipelinePolicy>();

            policies.AddRange(options.PerCallPolicies);

            if (!options.DisableTelemetry)
            {
                policies.Add(new TelemetryPolicy(options.GetType().Assembly, options.ApplicationId));
            }

            policies.AddRange(clientPolicies);

            policies.AddRange(options.PerRetryPolicies);

            policies.RemoveAll(policy => policy == null);

            return(new HttpPipeline(options.Transport, policies.ToArray(), options.ResponseClassifier, options.ServiceProvider));
        }
示例#12
0
            public RetriableStreamImpl(Stream initialStream, Func <long, Stream> streamFactory, Func <long, ValueTask <Stream> > asyncStreamFactory, ResponseClassifier responseClassifier, int maxRetries)
            {
                if (initialStream.CanSeek)
                {
                    try
                    {
                        _length = EnsureStream(initialStream).Length;
                    }
                    catch
                    {
                        // ignore
                    }
                }

                _currentStream      = EnsureStream(initialStream);
                _streamFactory      = streamFactory;
                _responseClassifier = responseClassifier;
                _asyncStreamFactory = asyncStreamFactory;
                _maxRetries         = maxRetries;
            }
示例#13
0
 /// <summary>
 /// </summary>
 public ExceptionFormattingResponseClassifier(ResponseClassifier responseClassifier, DiagnosticsOptions diagnostics)
 {
     _responseClassifier = responseClassifier;
     MessageSanitizer    = ClientDiagnostics.CreateMessageSanitizer(diagnostics);
 }
示例#14
0
        /// <summary>
        /// Creates an instance of <see cref="HttpPipeline"/> populated with default policies, customer provided policies from <paramref name="options"/> and client provided per call policies.
        /// </summary>
        /// <param name="options">The customer provided client options object.</param>
        /// <param name="perCallPolicies">Client provided per-call policies.</param>
        /// <param name="perRetryPolicies">Client provided per-retry policies.</param>
        /// <param name="responseClassifier">The client provided response classifier.</param>
        /// <returns>A new instance of <see cref="HttpPipeline"/></returns>
        public static HttpPipeline Build(ClientOptions options, HttpPipelinePolicy[] perCallPolicies, HttpPipelinePolicy[] perRetryPolicies, ResponseClassifier responseClassifier)
        {
            if (perCallPolicies == null)
            {
                throw new ArgumentNullException(nameof(perCallPolicies));
            }

            if (perRetryPolicies == null)
            {
                throw new ArgumentNullException(nameof(perRetryPolicies));
            }

            var policies = new List <HttpPipelinePolicy>(8 +
                                                         (options.Policies?.Count ?? 0) +
                                                         perCallPolicies.Length +
                                                         perRetryPolicies.Length);

            void AddCustomerPolicies(HttpPipelinePosition position)
            {
                if (options.Policies != null)
                {
                    foreach (var policy in options.Policies)
                    {
                        if (policy.Position == position)
                        {
                            policies.Add(policy.Policy);
                        }
                    }
                }
            }

            bool isDistributedTracingEnabled = options.Diagnostics.IsDistributedTracingEnabled;

            policies.Add(ReadClientRequestIdPolicy.Shared);

            policies.AddRange(perCallPolicies);

            AddCustomerPolicies(HttpPipelinePosition.PerCall);

            policies.Add(ClientRequestIdPolicy.Shared);

            DiagnosticsOptions diagnostics = options.Diagnostics;

            if (diagnostics.IsTelemetryEnabled)
            {
                policies.Add(CreateTelemetryPolicy(options));
            }

            RetryOptions retryOptions = options.Retry;

            policies.Add(new RetryPolicy(retryOptions.Mode, retryOptions.Delay, retryOptions.MaxDelay, retryOptions.MaxRetries));

            policies.Add(RedirectPolicy.Shared);

            policies.AddRange(perRetryPolicies);

            AddCustomerPolicies(HttpPipelinePosition.PerRetry);

            if (diagnostics.IsLoggingEnabled)
            {
                string assemblyName = options.GetType().Assembly !.GetName().Name !;

                policies.Add(new LoggingPolicy(diagnostics.IsLoggingContentEnabled, diagnostics.LoggedContentSizeLimit,
                                               diagnostics.LoggedHeaderNames.ToArray(), diagnostics.LoggedQueryParameters.ToArray(), assemblyName));
            }

            policies.Add(new ResponseBodyPolicy(options.Retry.NetworkTimeout));

            policies.Add(new RequestActivityPolicy(isDistributedTracingEnabled, ClientDiagnostics.GetResourceProviderNamespace(options.GetType().Assembly)));

            AddCustomerPolicies(HttpPipelinePosition.BeforeTransport);

            policies.RemoveAll(static policy => policy == null);
 /// <summary>
 /// Creates a new instance of <see cref="HttpPipeline"/> with the provided transport, policies and response classifier.
 /// </summary>
 /// <param name="transport">The <see cref="HttpPipelineTransport"/> to use for sending the requests.</param>
 /// <param name="perCallIndex"></param>
 /// <param name="perRetryIndex"></param>
 /// <param name="policies">Policies to be invoked as part of the pipeline in order.</param>
 /// <param name="responseClassifier">The response classifier to be used in invocations.</param>
 /// <param name="isTransportOwnedInternally"> </param>
 internal DisposableHttpPipeline(HttpPipelineTransport transport, int perCallIndex, int perRetryIndex, HttpPipelinePolicy[] policies, ResponseClassifier responseClassifier, bool isTransportOwnedInternally)
     : base(transport, perCallIndex, perRetryIndex, policies, responseClassifier)
 {
     this.isTransportOwnedInternally = isTransportOwnedInternally;
 }
        public static HttpPipeline Build(ClientOptions options, HttpPipelinePolicy[] perCallClientPolicies, HttpPipelinePolicy[] perRetryClientPolicies, ResponseClassifier responseClassifier)
        {
            if (perCallClientPolicies == null)
            {
                throw new ArgumentNullException(nameof(perCallClientPolicies));
            }

            if (perRetryClientPolicies == null)
            {
                throw new ArgumentNullException(nameof(perRetryClientPolicies));
            }

            var policies = new List <HttpPipelinePolicy>();

            bool isDistributedTracingEnabled = options.Diagnostics.IsDistributedTracingEnabled;

            policies.AddRange(perCallClientPolicies);

            policies.AddRange(options.PerCallPolicies);

            policies.Add(ClientRequestIdPolicy.Shared);

            DiagnosticsOptions diagnostics = options.Diagnostics;

            if (diagnostics.IsTelemetryEnabled)
            {
                policies.Add(CreateTelemetryPolicy(options));
            }

            RetryOptions retryOptions = options.Retry;

            policies.Add(new RetryPolicy(retryOptions.Mode, retryOptions.Delay, retryOptions.MaxDelay, retryOptions.MaxRetries));

            policies.AddRange(perRetryClientPolicies);

            policies.AddRange(options.PerRetryPolicies);

            if (diagnostics.IsLoggingEnabled)
            {
                policies.Add(new LoggingPolicy(diagnostics.IsLoggingContentEnabled, diagnostics.LoggingContentSizeLimit,
                                               diagnostics.LoggingAllowedHeaderNames.ToArray(), diagnostics.LoggingAllowedQueryParameters.ToArray()));
            }

            policies.Add(BufferResponsePolicy.Shared);

            policies.Add(new RequestActivityPolicy(isDistributedTracingEnabled));

            policies.RemoveAll(policy => policy == null);

            return(new HttpPipeline(options.Transport,
                                    policies.ToArray(),
                                    responseClassifier,
                                    new ClientDiagnostics(isDistributedTracingEnabled)));
        }
示例#17
0
 public HttpPipelineMessage(Request request, ResponseClassifier responseClassifier, CancellationToken cancellationToken)
 {
     Request            = request;
     ResponseClassifier = responseClassifier;
     CancellationToken  = cancellationToken;
 }
        /// <summary>
        /// Creates an instance of <see cref="HttpPipeline"/> populated with default policies, customer provided policies from <paramref name="options"/> and client provided per call policies.
        /// </summary>
        /// <param name="options">The customer provided client options object.</param>
        /// <param name="perCallPolicies">Client provided per-call policies.</param>
        /// <param name="perRetryPolicies">Client provided per-retry policies.</param>
        /// <param name="responseClassifier">The client provided response classifier.</param>
        /// <returns>A new instance of <see cref="HttpPipeline"/></returns>
        public static HttpPipeline Build(ClientOptions options, HttpPipelinePolicy[] perCallPolicies, HttpPipelinePolicy[] perRetryPolicies, ResponseClassifier responseClassifier)
        {
            if (perCallPolicies == null)
            {
                throw new ArgumentNullException(nameof(perCallPolicies));
            }

            if (perRetryPolicies == null)
            {
                throw new ArgumentNullException(nameof(perRetryPolicies));
            }

            var policies = new List <HttpPipelinePolicy>();

            bool isDistributedTracingEnabled = options.Diagnostics.IsDistributedTracingEnabled;

            policies.Add(ReadClientRequestIdPolicy.Shared);

            policies.AddRange(perCallPolicies);

            policies.AddRange(options.PerCallPolicies);

            policies.Add(ClientRequestIdPolicy.Shared);

            DiagnosticsOptions diagnostics = options.Diagnostics;

            if (diagnostics.IsTelemetryEnabled)
            {
                policies.Add(CreateTelemetryPolicy(options));
            }

            RetryOptions retryOptions = options.Retry;

            policies.Add(new RetryPolicy(retryOptions.Mode, retryOptions.Delay, retryOptions.MaxDelay, retryOptions.MaxRetries));

            policies.AddRange(perRetryPolicies);

            policies.AddRange(options.PerRetryPolicies);

            if (diagnostics.IsLoggingEnabled)
            {
                string assemblyName = options.GetType().Assembly !.GetName().Name !;

                policies.Add(new LoggingPolicy(diagnostics.IsLoggingContentEnabled, diagnostics.LoggedContentSizeLimit,
                                               diagnostics.LoggedHeaderNames.ToArray(), diagnostics.LoggedQueryParameters.ToArray(), assemblyName));
            }

            policies.Add(new ResponseBodyPolicy(options.Retry.NetworkTimeout));

            policies.Add(new RequestActivityPolicy(isDistributedTracingEnabled, ClientDiagnostics.GetResourceProviderNamespace(options.GetType().Assembly)));

            policies.RemoveAll(policy => policy == null);

            return(new HttpPipeline(options.Transport,
                                    policies.ToArray(),
                                    responseClassifier));
        }
示例#19
0
 public HttpPipelineMessage(Request request, ResponseClassifier responseClassifier)
 {
     Request            = request;
     ResponseClassifier = responseClassifier;
     BufferResponse     = true;
 }
        public static HttpPipeline Build(ClientOptions options, HttpPipelinePolicy[] perCallClientPolicies, HttpPipelinePolicy[] perRetryClientPolicies, ResponseClassifier responseClassifier)
        {
            if (perCallClientPolicies == null)
            {
                throw new ArgumentNullException(nameof(perCallClientPolicies));
            }

            if (perRetryClientPolicies == null)
            {
                throw new ArgumentNullException(nameof(perRetryClientPolicies));
            }

            var policies = new List <HttpPipelinePolicy>();

            policies.AddRange(perCallClientPolicies);

            policies.AddRange(options.PerCallPolicies);

            policies.Add(ClientRequestIdPolicy.Shared);

            if (options.Diagnostics.IsTelemetryEnabled)
            {
                policies.Add(CreateTelemetryPolicy(options));
            }

            RetryOptions retryOptions = options.Retry;

            policies.Add(new RetryPolicy(retryOptions.Mode, retryOptions.Delay, retryOptions.MaxDelay, retryOptions.MaxRetries));

            policies.AddRange(perRetryClientPolicies);

            policies.AddRange(options.PerRetryPolicies);

            if (options.Diagnostics.IsLoggingEnabled)
            {
                policies.Add(LoggingPolicy.Shared);
            }

            policies.Add(BufferResponsePolicy.Shared);

            policies.Add(new RequestActivityPolicy());

            policies.RemoveAll(policy => policy == null);

            return(new HttpPipeline(options.Transport, policies.ToArray(), responseClassifier, new ClientDiagnostics(options.Diagnostics.IsLoggingEnabled)));
        }
 /// <summary>
 /// Creates a new instance of <see cref="HttpPipeline"/> with the provided transport, policies and response classifier.
 /// </summary>
 /// <param name="transport">The <see cref="HttpPipelineTransport"/> to use for sending the requests.</param>
 /// <param name="perCallIndex"></param>
 /// <param name="perRetryIndex"></param>
 /// <param name="policies">Policies to be invoked as part of the pipeline in order.</param>
 /// <param name="responseClassifier">The response classifier to be used in invocations.</param>
 internal DisposableHttpPipeline(HttpPipelineTransport transport, int perCallIndex, int perRetryIndex, HttpPipelinePolicy[] policies, ResponseClassifier responseClassifier)
     : base(transport, perCallIndex, perRetryIndex, policies, responseClassifier)
 {
 }
示例#22
0
 protected ClientOptions()
 {
     Retry              = new RetryOptions();
     Diagnostics        = new DiagnosticsOptions();
     ResponseClassifier = new ResponseClassifier();
 }