| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | #nullable enable |
| | 5 | |
|
| | 6 | | using System; |
| | 7 | | using System.Threading.Tasks; |
| | 8 | |
|
| | 9 | | namespace Azure.Core.Pipeline |
| | 10 | | { |
| | 11 | | /// <summary> |
| | 12 | | /// Represent an extension point for the <see cref="HttpPipeline"/> that can mutate the <see cref="Request"/> and re |
| | 13 | | /// </summary> |
| | 14 | | public abstract class HttpPipelinePolicy |
| | 15 | | { |
| | 16 | | /// <summary> |
| | 17 | | /// Applies the policy to the <paramref name="message"/>. Implementers are expected to mutate <see cref="HttpMes |
| | 18 | | /// </summary> |
| | 19 | | /// <param name="message">The <see cref="HttpMessage"/> this policy would be applied to.</param> |
| | 20 | | /// <param name="pipeline">The set of <see cref="HttpPipelinePolicy"/> to execute after current one.</param> |
| | 21 | | /// <returns>The <see cref="ValueTask"/> representing the asynchronous operation.</returns> |
| | 22 | | public abstract ValueTask ProcessAsync(HttpMessage message, ReadOnlyMemory<HttpPipelinePolicy> pipeline); |
| | 23 | |
|
| | 24 | | /// <summary> |
| | 25 | | /// Applies the policy to the <paramref name="message"/>. Implementers are expected to mutate <see cref="HttpMes |
| | 26 | | /// </summary> |
| | 27 | | /// <param name="message">The <see cref="HttpMessage"/> this policy would be applied to.</param> |
| | 28 | | /// <param name="pipeline">The set of <see cref="HttpPipelinePolicy"/> to execute after current one.</param> |
| | 29 | | public abstract void Process(HttpMessage message, ReadOnlyMemory<HttpPipelinePolicy> pipeline); |
| | 30 | |
|
| | 31 | | /// <summary> |
| | 32 | | /// Invokes the next <see cref="HttpPipelinePolicy"/> in the <paramref name="pipeline"/>. |
| | 33 | | /// </summary> |
| | 34 | | /// <param name="message">The <see cref="HttpMessage"/> next policy would be applied to.</param> |
| | 35 | | /// <param name="pipeline">The set of <see cref="HttpPipelinePolicy"/> to execute after next one.</param> |
| | 36 | | /// <returns>The <see cref="ValueTask"/> representing the asynchronous operation.</returns> |
| | 37 | | protected static ValueTask ProcessNextAsync(HttpMessage message, ReadOnlyMemory<HttpPipelinePolicy> pipeline) |
| | 38 | | { |
| 7166 | 39 | | return pipeline.Span[0].ProcessAsync(message, pipeline.Slice(1)); |
| | 40 | | } |
| | 41 | |
|
| | 42 | | /// <summary> |
| | 43 | | /// Invokes the next <see cref="HttpPipelinePolicy"/> in the <paramref name="pipeline"/>. |
| | 44 | | /// </summary> |
| | 45 | | /// <param name="message">The <see cref="HttpMessage"/> next policy would be applied to.</param> |
| | 46 | | /// <param name="pipeline">The set of <see cref="HttpPipelinePolicy"/> to execute after next one.</param> |
| | 47 | | protected static void ProcessNext(HttpMessage message, ReadOnlyMemory<HttpPipelinePolicy> pipeline) |
| | 48 | | { |
| 7020 | 49 | | pipeline.Span[0].Process(message, pipeline.Slice(1)); |
| 6950 | 50 | | } |
| | 51 | | } |
| | 52 | | } |