#if ! NET6_0_OR_GREATER using System.Threading; using System.Threading.Tasks; namespace System.Net.Http { /// /// Extension methods for s. /// /// /// Copied from .NET 6 runtime / HttpClient. /// [Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] internal static class HttpClientExtensions { private static readonly HttpMethod _httpMethodPatch = new("PATCH"); /// /// Sends a PATCH request with a cancellation token to a Uri represented as a string as an asynchronous operation. /// /// A instance. /// The Uri the request is sent to. /// The HTTP request content sent to the server. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// The task object representing the asynchronous operation. public static Task PatchAsync(this HttpClient client, string? requestUri, HttpContent? content, CancellationToken cancellationToken) => client.PatchAsync(CreateUri(requestUri), content, cancellationToken); /// /// Sends a PATCH request with a cancellation token as an asynchronous operation. /// /// A instance. /// The Uri the request is sent to. /// The HTTP request content sent to the server. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// The task object representing the asynchrnous operation. public static Task PatchAsync(this HttpClient client, Uri? requestUri, HttpContent? content, CancellationToken cancellationToken) { var request = new HttpRequestMessage(_httpMethodPatch, requestUri) { Version = HttpVersion.Version11, Content = content, }; return client.SendAsync(request, cancellationToken); } private static Uri? CreateUri(string? uri) => string.IsNullOrEmpty(uri) ? null : new Uri(uri, UriKind.RelativeOrAbsolute); } } #endif