From 4934255f2dd66f03db58eab094f7fca4b8e0992b Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Sun, 15 Mar 2026 13:15:25 +1100 Subject: [PATCH 1/3] Add more Http APIs Add HttpClient.Send, PatchAsync, and HttpContent CopyToAsync/LoadIntoBufferAsync polyfills --- apiCount.include.md | 34 +++++------ api_list.include.md | 8 +++ assemblySize.include.md | 58 +++++++++---------- src/Consume/Consume.cs | 8 +++ src/Polyfill/Polyfill_HttpClient.cs | 44 ++++++++++++++ src/Polyfill/Polyfill_HttpContent.cs | 58 +++++++++++++++++++ src/Split/net461/Polyfill_HttpClient.cs | 34 +++++++++++ src/Split/net461/Polyfill_HttpContent.cs | 48 +++++++++++++++ src/Split/net462/Polyfill_HttpClient.cs | 34 +++++++++++ src/Split/net462/Polyfill_HttpContent.cs | 48 +++++++++++++++ src/Split/net47/Polyfill_HttpClient.cs | 34 +++++++++++ src/Split/net47/Polyfill_HttpContent.cs | 48 +++++++++++++++ src/Split/net471/Polyfill_HttpClient.cs | 34 +++++++++++ src/Split/net471/Polyfill_HttpContent.cs | 48 +++++++++++++++ src/Split/net472/Polyfill_HttpClient.cs | 34 +++++++++++ src/Split/net472/Polyfill_HttpContent.cs | 48 +++++++++++++++ src/Split/net48/Polyfill_HttpClient.cs | 34 +++++++++++ src/Split/net48/Polyfill_HttpContent.cs | 48 +++++++++++++++ src/Split/net481/Polyfill_HttpClient.cs | 34 +++++++++++ src/Split/net481/Polyfill_HttpContent.cs | 48 +++++++++++++++ src/Split/net5.0/Polyfill_HttpContent.cs | 23 ++++++++ src/Split/net6.0/Polyfill_HttpContent.cs | 35 +++++++++++ src/Split/net7.0/Polyfill_HttpContent.cs | 35 +++++++++++ src/Split/net8.0/Polyfill_HttpContent.cs | 35 +++++++++++ .../netcoreapp2.0/Polyfill_HttpClient.cs | 34 +++++++++++ .../netcoreapp2.0/Polyfill_HttpContent.cs | 48 +++++++++++++++ .../netcoreapp2.1/Polyfill_HttpContent.cs | 48 +++++++++++++++ .../netcoreapp2.2/Polyfill_HttpContent.cs | 48 +++++++++++++++ .../netcoreapp3.0/Polyfill_HttpContent.cs | 48 +++++++++++++++ .../netcoreapp3.1/Polyfill_HttpContent.cs | 48 +++++++++++++++ .../netstandard2.0/Polyfill_HttpClient.cs | 34 +++++++++++ .../netstandard2.0/Polyfill_HttpContent.cs | 48 +++++++++++++++ .../netstandard2.1/Polyfill_HttpContent.cs | 48 +++++++++++++++ src/Split/uap10.0/Polyfill_HttpClient.cs | 34 +++++++++++ src/Split/uap10.0/Polyfill_HttpContent.cs | 48 +++++++++++++++ src/Tests/PolyfillTests_HttpClient.cs | 46 +++++++++++++++ src/Tests/PolyfillTests_HttpContent.cs | 36 ++++++++++++ 37 files changed, 1434 insertions(+), 46 deletions(-) create mode 100644 src/Split/net6.0/Polyfill_HttpContent.cs create mode 100644 src/Split/net7.0/Polyfill_HttpContent.cs create mode 100644 src/Split/net8.0/Polyfill_HttpContent.cs diff --git a/apiCount.include.md b/apiCount.include.md index 06833fd9..fc7f1fca 100644 --- a/apiCount.include.md +++ b/apiCount.include.md @@ -1,28 +1,28 @@ -**API count: 825** +**API count: 833** ### Per Target Framework | Target | APIs | | -- | -- | -| `net461` | 789 | -| `net462` | 789 | -| `net47` | 788 | -| `net471` | 788 | -| `net472` | 784 | -| `net48` | 784 | -| `net481` | 784 | -| `netstandard2.0` | 787 | -| `netstandard2.1` | 628 | -| `netcoreapp2.0` | 710 | -| `netcoreapp2.1` | 640 | -| `netcoreapp2.2` | 640 | -| `netcoreapp3.0` | 587 | -| `netcoreapp3.1` | 586 | +| `net461` | 793 | +| `net462` | 793 | +| `net47` | 792 | +| `net471` | 792 | +| `net472` | 788 | +| `net48` | 788 | +| `net481` | 788 | +| `netstandard2.0` | 791 | +| `netstandard2.1` | 632 | +| `netcoreapp2.0` | 714 | +| `netcoreapp2.1` | 644 | +| `netcoreapp2.2` | 644 | +| `netcoreapp3.0` | 591 | +| `netcoreapp3.1` | 590 | | `net5.0` | 470 | | `net6.0` | 389 | | `net7.0` | 276 | | `net8.0` | 178 | | `net9.0` | 120 | | `net10.0` | 75 | -| `net11.0` | 60 | -| `uap10.0` | 776 | +| `net11.0` | 57 | +| `uap10.0` | 780 | diff --git a/api_list.include.md b/api_list.include.md index 9d5eaa49..50df1b6a 100644 --- a/api_list.include.md +++ b/api_list.include.md @@ -375,6 +375,10 @@ * `Task GetStreamAsync(Uri, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.getstreamasync?view=net-11.0#system-net-http-httpclient-getstreamasync(system-uri-system-threading-cancellationtoken)) * `Task GetStringAsync(string, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.getstringasync?view=net-11.0#system-net-http-httpclient-getstringasync(system-string-system-threading-cancellationtoken)) * `Task GetStringAsync(Uri, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.getstringasync?view=net-11.0#system-net-http-httpclient-getstringasync(system-uri-system-threading-cancellationtoken)) + * `Task PatchAsync(string?, HttpContent?, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.patchasync?view=net-11.0#system-net-http-httpclient-patchasync(system-string-system-net-http-httpcontent-system-threading-cancellationtoken)) + * `Task PatchAsync(string?, HttpContent?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.patchasync?view=net-11.0#system-net-http-httpclient-patchasync(system-string-system-net-http-httpcontent)) + * `Task PatchAsync(Uri?, HttpContent?, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.patchasync?view=net-11.0#system-net-http-httpclient-patchasync(system-uri-system-net-http-httpcontent-system-threading-cancellationtoken)) + * `Task PatchAsync(Uri?, HttpContent?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.patchasync?view=net-11.0#system-net-http-httpclient-patchasync(system-uri-system-net-http-httpcontent)) * `HttpResponseMessage Send(HttpRequestMessage, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.send?view=net-11.0#system-net-http-httpclient-send(system-net-http-httprequestmessage-system-threading-cancellationtoken)) * `HttpResponseMessage Send(HttpRequestMessage, HttpCompletionOption, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.send?view=net-11.0#system-net-http-httpclient-send(system-net-http-httprequestmessage-system-net-http-httpcompletionoption-system-threading-cancellationtoken)) * `HttpResponseMessage Send(HttpRequestMessage, HttpCompletionOption)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.send?view=net-11.0#system-net-http-httpclient-send(system-net-http-httprequestmessage-system-net-http-httpcompletionoption)) @@ -384,6 +388,10 @@ #### HttpContent * `void CopyTo(Stream, System.Net.TransportContext?, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpcontent.copyto?view=net-11.0) + * `Task CopyToAsync(Stream, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpcontent.copytoasync?view=net-11.0#system-net-http-httpcontent-copytoasync(system-io-stream-system-threading-cancellationtoken)) + * `Task CopyToAsync(Stream, System.Net.TransportContext?, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpcontent.copytoasync?view=net-11.0#system-net-http-httpcontent-copytoasync(system-io-stream-system-net-transportcontext-system-threading-cancellationtoken)) + * `Task LoadIntoBufferAsync(CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpcontent.loadintobufferasync?view=net-11.0#system-net-http-httpcontent-loadintobufferasync(system-threading-cancellationtoken)) + * `Task LoadIntoBufferAsync(long, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpcontent.loadintobufferasync?view=net-11.0#system-net-http-httpcontent-loadintobufferasync(system-int64-system-threading-cancellationtoken)) * `Task ReadAsByteArrayAsync(CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpcontent.readasbytearrayasync?view=net-11.0#system-net-http-httpcontent-readasbytearrayasync(system-threading-cancellationtoken)) * `Stream ReadAsStream(CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpcontent.readasstream?view=net-11.0#system-net-http-httpcontent-readasstream(system-threading-cancellationtoken)) * `Task ReadAsStreamAsync(CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpcontent.readasstreamasync?view=net-11.0#system-net-http-httpcontent-readasstreamasync(system-threading-cancellationtoken)) diff --git a/assemblySize.include.md b/assemblySize.include.md index db7cd7e3..f76638ae 100644 --- a/assemblySize.include.md +++ b/assemblySize.include.md @@ -4,49 +4,49 @@ |----------------|----------------|---------------|-----------|-----------|--------------------|---------------------|-------------| | netstandard2.0 | 8.0KB | 259.5KB | +251.5KB | +9.0KB | +6.0KB | +9.0KB | +13.5KB | | netstandard2.1 | 8.5KB | 212.5KB | +204.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | -| net461 | 8.5KB | 266.0KB | +257.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net462 | 7.0KB | 265.0KB | +258.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net47 | 7.0KB | 264.5KB | +257.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net471 | 8.5KB | 264.5KB | +256.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net472 | 8.5KB | 263.5KB | +255.0KB | +9.0KB | +6.0KB | +9.0KB | +13.5KB | -| net48 | 8.5KB | 263.0KB | +254.5KB | +9.0KB | +6.5KB | +9.5KB | +13.5KB | -| net481 | 8.5KB | 263.5KB | +255.0KB | +9.0KB | +6.0KB | +9.0KB | +13.5KB | -| netcoreapp2.0 | 9.0KB | 239.0KB | +230.0KB | +9.5KB | +6.5KB | +9.5KB | +14.0KB | -| netcoreapp2.1 | 9.0KB | 220.5KB | +211.5KB | +9.0KB | +6.0KB | +9.0KB | +13.5KB | -| netcoreapp2.2 | 9.0KB | 220.5KB | +211.5KB | +9.0KB | +6.0KB | +9.0KB | +13.5KB | -| netcoreapp3.0 | 9.5KB | 211.0KB | +201.5KB | +9.5KB | +6.5KB | +9.5KB | +14.0KB | -| netcoreapp3.1 | 9.5KB | 209.5KB | +200.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | +| net461 | 8.5KB | 266.5KB | +258.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net462 | 7.0KB | 265.5KB | +258.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net47 | 7.0KB | 265.0KB | +258.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net471 | 8.5KB | 265.0KB | +256.5KB | +9.0KB | +6.5KB | +9.5KB | +13.5KB | +| net472 | 8.5KB | 264.0KB | +255.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net48 | 8.5KB | 264.0KB | +255.5KB | +9.0KB | +6.0KB | +9.0KB | +13.5KB | +| net481 | 8.5KB | 264.0KB | +255.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| netcoreapp2.0 | 9.0KB | 240.0KB | +231.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| netcoreapp2.1 | 9.0KB | 221.0KB | +212.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | +| netcoreapp2.2 | 9.0KB | 221.0KB | +212.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | +| netcoreapp3.0 | 9.5KB | 211.5KB | +202.0KB | +9.5KB | +6.5KB | +9.5KB | +14.0KB | +| netcoreapp3.1 | 9.5KB | 210.0KB | +200.5KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | | net5.0 | 9.5KB | 173.0KB | +163.5KB | +9.0KB | +6.0KB | +9.0KB | +14.0KB | | net6.0 | 10.0KB | 128.0KB | +118.0KB | +10.0KB | +6.5KB | +512bytes | +3.5KB | | net7.0 | 10.0KB | 98.0KB | +88.0KB | +9.5KB | +5.5KB | +512bytes | +3.5KB | | net8.0 | 9.5KB | 79.5KB | +70.0KB | +8.5KB | | +512bytes | +3.5KB | | net9.0 | 9.5KB | 45.0KB | +35.5KB | +8.5KB | | +512bytes | +3.5KB | | net10.0 | 10.0KB | 23.5KB | +13.5KB | +9.0KB | | +512bytes | +3.5KB | -| net11.0 | 10.0KB | 19.0KB | +9.0KB | +9.5KB | | +1.0KB | +4.0KB | +| net11.0 | 10.0KB | 18.0KB | +8.0KB | +9.5KB | | +1.0KB | +4.0KB | ### Assembly Sizes with EmbedUntrackedSources | | Empty Assembly | With Polyfill | Diff | Ensure | ArgumentExceptions | StringInterpolation | Nullability | |----------------|----------------|---------------|-----------|-----------|--------------------|---------------------|-------------| -| netstandard2.0 | 8.0KB | 383.6KB | +375.6KB | +16.7KB | +7.7KB | +13.9KB | +18.9KB | -| netstandard2.1 | 8.5KB | 311.6KB | +303.1KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | -| net461 | 8.5KB | 390.6KB | +382.1KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net462 | 7.0KB | 389.6KB | +382.6KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net47 | 7.0KB | 388.8KB | +381.8KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net471 | 8.5KB | 388.8KB | +380.3KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net472 | 8.5KB | 386.8KB | +378.3KB | +16.7KB | +7.7KB | +13.9KB | +18.9KB | -| net48 | 8.5KB | 386.3KB | +377.8KB | +16.7KB | +8.2KB | +14.4KB | +18.9KB | -| net481 | 8.5KB | 386.8KB | +378.3KB | +16.7KB | +7.7KB | +13.9KB | +18.9KB | -| netcoreapp2.0 | 9.0KB | 353.0KB | +344.0KB | +17.2KB | +8.2KB | +14.4KB | +19.4KB | -| netcoreapp2.1 | 9.0KB | 323.8KB | +314.8KB | +16.7KB | +7.7KB | +13.9KB | +18.9KB | -| netcoreapp2.2 | 9.0KB | 323.8KB | +314.8KB | +16.7KB | +7.7KB | +13.9KB | +18.9KB | -| netcoreapp3.0 | 9.5KB | 305.1KB | +295.6KB | +17.2KB | +8.2KB | +14.4KB | +19.4KB | -| netcoreapp3.1 | 9.5KB | 303.6KB | +294.1KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | +| netstandard2.0 | 8.0KB | 383.8KB | +375.8KB | +16.7KB | +7.7KB | +13.9KB | +18.9KB | +| netstandard2.1 | 8.5KB | 311.7KB | +303.2KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | +| net461 | 8.5KB | 391.2KB | +382.7KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net462 | 7.0KB | 390.2KB | +383.2KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net47 | 7.0KB | 389.5KB | +382.5KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net471 | 8.5KB | 389.5KB | +381.0KB | +16.7KB | +8.2KB | +14.4KB | +18.9KB | +| net472 | 8.5KB | 387.4KB | +378.9KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net48 | 8.5KB | 387.4KB | +378.9KB | +16.7KB | +7.7KB | +13.9KB | +18.9KB | +| net481 | 8.5KB | 387.4KB | +378.9KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| netcoreapp2.0 | 9.0KB | 354.1KB | +345.1KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| netcoreapp2.1 | 9.0KB | 324.4KB | +315.4KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | +| netcoreapp2.2 | 9.0KB | 324.4KB | +315.4KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | +| netcoreapp3.0 | 9.5KB | 305.8KB | +296.3KB | +17.2KB | +8.2KB | +14.4KB | +19.4KB | +| netcoreapp3.1 | 9.5KB | 304.2KB | +294.7KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | | net5.0 | 9.5KB | 249.9KB | +240.4KB | +16.7KB | +7.7KB | +13.9KB | +19.4KB | | net6.0 | 10.0KB | 188.2KB | +178.2KB | +17.7KB | +8.2KB | +1.1KB | +4.2KB | | net7.0 | 10.0KB | 141.3KB | +131.3KB | +17.1KB | +6.9KB | +1.1KB | +4.2KB | | net8.0 | 9.5KB | 112.8KB | +103.3KB | +16.0KB | +299bytes | +1.1KB | +4.2KB | | net9.0 | 9.5KB | 64.6KB | +55.1KB | +16.0KB | | +1.1KB | +4.2KB | -| net10.0 | 10.0KB | 35.8KB | +25.8KB | +16.5KB | | +1.1KB | +4.2KB | -| net11.0 | 10.0KB | 28.5KB | +18.5KB | +17.0KB | | +1.6KB | +4.7KB | +| net10.0 | 10.0KB | 35.7KB | +25.7KB | +16.5KB | | +1.1KB | +4.2KB | +| net11.0 | 10.0KB | 26.9KB | +16.9KB | +17.0KB | | +1.6KB | +4.7KB | diff --git a/src/Consume/Consume.cs b/src/Consume/Consume.cs index 329ca115..f4430660 100644 --- a/src/Consume/Consume.cs +++ b/src/Consume/Consume.cs @@ -748,6 +748,10 @@ void HashSet_Methods() #if FeatureHttp void HttpClient_Methods(HttpClient target) { + target.PatchAsync("", null); + target.PatchAsync(new Uri("http://a"), null); + target.PatchAsync("", null, CancellationToken.None); + target.PatchAsync(new Uri("http://a"), null, CancellationToken.None); target.Send(new HttpRequestMessage()); target.Send(new HttpRequestMessage(), HttpCompletionOption.ResponseContentRead); target.Send(new HttpRequestMessage(), CancellationToken.None); @@ -765,9 +769,13 @@ void HttpContent_Methods(ByteArrayContent target) target.ReadAsStream(); target.ReadAsStream(CancellationToken.None); target.CopyTo(System.IO.Stream.Null, null, CancellationToken.None); + target.CopyToAsync(System.IO.Stream.Null, CancellationToken.None); + target.CopyToAsync(System.IO.Stream.Null, null, CancellationToken.None); target.ReadAsStreamAsync(CancellationToken.None); target.ReadAsByteArrayAsync(CancellationToken.None); target.ReadAsStringAsync(CancellationToken.None); + target.LoadIntoBufferAsync(CancellationToken.None); + target.LoadIntoBufferAsync(1024, CancellationToken.None); } #endif diff --git a/src/Polyfill/Polyfill_HttpClient.cs b/src/Polyfill/Polyfill_HttpClient.cs index 8545b7be..375e6fb3 100644 --- a/src/Polyfill/Polyfill_HttpClient.cs +++ b/src/Polyfill/Polyfill_HttpClient.cs @@ -10,6 +10,50 @@ namespace Polyfills; static partial class Polyfill { +#if !NETCOREAPP2_1_OR_GREATER && !NETSTANDARD2_1_OR_GREATER + /// + /// Sends a PATCH request to a URI designated as a string as an asynchronous operation. + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.patchasync?view=net-11.0#system-net-http-httpclient-patchasync(system-string-system-net-http-httpcontent) + public static Task PatchAsync( + this HttpClient target, + string? requestUri, + HttpContent? content) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }); + + /// + /// Sends a PATCH request as an asynchronous operation. + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.patchasync?view=net-11.0#system-net-http-httpclient-patchasync(system-uri-system-net-http-httpcontent) + public static Task PatchAsync( + this HttpClient target, + Uri? requestUri, + HttpContent? content) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }); + + /// + /// Sends a PATCH request with a cancellation token to a URI represented as a string as an asynchronous operation. + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.patchasync?view=net-11.0#system-net-http-httpclient-patchasync(system-string-system-net-http-httpcontent-system-threading-cancellationtoken) + public static Task PatchAsync( + this HttpClient target, + string? requestUri, + HttpContent? content, + CancellationToken cancellationToken) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }, cancellationToken); + + /// + /// Sends a PATCH request with a cancellation token as an asynchronous operation. + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.patchasync?view=net-11.0#system-net-http-httpclient-patchasync(system-uri-system-net-http-httpcontent-system-threading-cancellationtoken) + public static Task PatchAsync( + this HttpClient target, + Uri? requestUri, + HttpContent? content, + CancellationToken cancellationToken) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }, cancellationToken); +#endif + #if !NET5_0_OR_GREATER /// /// Sends an HTTP request with the specified request. diff --git a/src/Polyfill/Polyfill_HttpContent.cs b/src/Polyfill/Polyfill_HttpContent.cs index b98330f9..a7341e23 100644 --- a/src/Polyfill/Polyfill_HttpContent.cs +++ b/src/Polyfill/Polyfill_HttpContent.cs @@ -20,6 +20,35 @@ public static Stream ReadAsStream( #endif #if !NET5_0_OR_GREATER + /// + /// Serializes the HTTP content into a stream of bytes and copies it to the stream object provided as the stream parameter. + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpcontent.copytoasync?view=net-11.0#system-net-http-httpcontent-copytoasync(system-io-stream-system-threading-cancellationtoken) + public static Task CopyToAsync( + this HttpContent target, + Stream stream, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.CopyToAsync(stream) + .WaitAsync(cancellationToken); + } + + /// + /// Serializes the HTTP content into a stream of bytes and copies it to the stream object provided as the stream parameter. + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpcontent.copytoasync?view=net-11.0#system-net-http-httpcontent-copytoasync(system-io-stream-system-net-transportcontext-system-threading-cancellationtoken) + public static Task CopyToAsync( + this HttpContent target, + Stream stream, + System.Net.TransportContext? context, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.CopyToAsync(stream, context) + .WaitAsync(cancellationToken); + } + /// /// Serializes the HTTP content into a stream. /// @@ -73,5 +102,34 @@ public static Task ReadAsStringAsync( .WaitAsync(cancellationToken); } #endif + +#if !NET9_0_OR_GREATER + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpcontent.loadintobufferasync?view=net-11.0#system-net-http-httpcontent-loadintobufferasync(system-threading-cancellationtoken) + public static Task LoadIntoBufferAsync( + this HttpContent target, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync() + .WaitAsync(cancellationToken); + } + + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpcontent.loadintobufferasync?view=net-11.0#system-net-http-httpcontent-loadintobufferasync(system-int64-system-threading-cancellationtoken) + public static Task LoadIntoBufferAsync( + this HttpContent target, + long maxBufferSize, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync(maxBufferSize) + .WaitAsync(cancellationToken); + } +#endif } #endif diff --git a/src/Split/net461/Polyfill_HttpClient.cs b/src/Split/net461/Polyfill_HttpClient.cs index f512269b..4a591775 100644 --- a/src/Split/net461/Polyfill_HttpClient.cs +++ b/src/Split/net461/Polyfill_HttpClient.cs @@ -10,6 +10,40 @@ namespace Polyfills; static partial class Polyfill { /// + /// Sends a PATCH request to a URI designated as a string as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + string? requestUri, + HttpContent? content) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }); + /// + /// Sends a PATCH request as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + Uri? requestUri, + HttpContent? content) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }); + /// + /// Sends a PATCH request with a cancellation token to a URI represented as a string as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + string? requestUri, + HttpContent? content, + CancellationToken cancellationToken) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }, cancellationToken); + /// + /// Sends a PATCH request with a cancellation token as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + Uri? requestUri, + HttpContent? content, + CancellationToken cancellationToken) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }, cancellationToken); + /// /// Sends an HTTP request with the specified request. /// public static HttpResponseMessage Send( diff --git a/src/Split/net461/Polyfill_HttpContent.cs b/src/Split/net461/Polyfill_HttpContent.cs index c2df4408..9105beb0 100644 --- a/src/Split/net461/Polyfill_HttpContent.cs +++ b/src/Split/net461/Polyfill_HttpContent.cs @@ -16,6 +16,31 @@ public static Stream ReadAsStream( CancellationToken cancellationToken = default) => target.ReadAsStreamAsync(cancellationToken).GetAwaiter().GetResult(); /// + /// Serializes the HTTP content into a stream of bytes and copies it to the stream object provided as the stream parameter. + /// + public static Task CopyToAsync( + this HttpContent target, + Stream stream, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.CopyToAsync(stream) + .WaitAsync(cancellationToken); + } + /// + /// Serializes the HTTP content into a stream of bytes and copies it to the stream object provided as the stream parameter. + /// + public static Task CopyToAsync( + this HttpContent target, + Stream stream, + System.Net.TransportContext? context, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.CopyToAsync(stream, context) + .WaitAsync(cancellationToken); + } + /// /// Serializes the HTTP content into a stream. /// public static void CopyTo( @@ -60,5 +85,28 @@ public static Task ReadAsStringAsync( return target.ReadAsStringAsync() .WaitAsync(cancellationToken); } + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync() + .WaitAsync(cancellationToken); + } + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + long maxBufferSize, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync(maxBufferSize) + .WaitAsync(cancellationToken); + } } #endif diff --git a/src/Split/net462/Polyfill_HttpClient.cs b/src/Split/net462/Polyfill_HttpClient.cs index f512269b..4a591775 100644 --- a/src/Split/net462/Polyfill_HttpClient.cs +++ b/src/Split/net462/Polyfill_HttpClient.cs @@ -10,6 +10,40 @@ namespace Polyfills; static partial class Polyfill { /// + /// Sends a PATCH request to a URI designated as a string as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + string? requestUri, + HttpContent? content) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }); + /// + /// Sends a PATCH request as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + Uri? requestUri, + HttpContent? content) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }); + /// + /// Sends a PATCH request with a cancellation token to a URI represented as a string as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + string? requestUri, + HttpContent? content, + CancellationToken cancellationToken) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }, cancellationToken); + /// + /// Sends a PATCH request with a cancellation token as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + Uri? requestUri, + HttpContent? content, + CancellationToken cancellationToken) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }, cancellationToken); + /// /// Sends an HTTP request with the specified request. /// public static HttpResponseMessage Send( diff --git a/src/Split/net462/Polyfill_HttpContent.cs b/src/Split/net462/Polyfill_HttpContent.cs index c2df4408..9105beb0 100644 --- a/src/Split/net462/Polyfill_HttpContent.cs +++ b/src/Split/net462/Polyfill_HttpContent.cs @@ -16,6 +16,31 @@ public static Stream ReadAsStream( CancellationToken cancellationToken = default) => target.ReadAsStreamAsync(cancellationToken).GetAwaiter().GetResult(); /// + /// Serializes the HTTP content into a stream of bytes and copies it to the stream object provided as the stream parameter. + /// + public static Task CopyToAsync( + this HttpContent target, + Stream stream, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.CopyToAsync(stream) + .WaitAsync(cancellationToken); + } + /// + /// Serializes the HTTP content into a stream of bytes and copies it to the stream object provided as the stream parameter. + /// + public static Task CopyToAsync( + this HttpContent target, + Stream stream, + System.Net.TransportContext? context, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.CopyToAsync(stream, context) + .WaitAsync(cancellationToken); + } + /// /// Serializes the HTTP content into a stream. /// public static void CopyTo( @@ -60,5 +85,28 @@ public static Task ReadAsStringAsync( return target.ReadAsStringAsync() .WaitAsync(cancellationToken); } + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync() + .WaitAsync(cancellationToken); + } + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + long maxBufferSize, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync(maxBufferSize) + .WaitAsync(cancellationToken); + } } #endif diff --git a/src/Split/net47/Polyfill_HttpClient.cs b/src/Split/net47/Polyfill_HttpClient.cs index f512269b..4a591775 100644 --- a/src/Split/net47/Polyfill_HttpClient.cs +++ b/src/Split/net47/Polyfill_HttpClient.cs @@ -10,6 +10,40 @@ namespace Polyfills; static partial class Polyfill { /// + /// Sends a PATCH request to a URI designated as a string as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + string? requestUri, + HttpContent? content) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }); + /// + /// Sends a PATCH request as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + Uri? requestUri, + HttpContent? content) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }); + /// + /// Sends a PATCH request with a cancellation token to a URI represented as a string as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + string? requestUri, + HttpContent? content, + CancellationToken cancellationToken) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }, cancellationToken); + /// + /// Sends a PATCH request with a cancellation token as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + Uri? requestUri, + HttpContent? content, + CancellationToken cancellationToken) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }, cancellationToken); + /// /// Sends an HTTP request with the specified request. /// public static HttpResponseMessage Send( diff --git a/src/Split/net47/Polyfill_HttpContent.cs b/src/Split/net47/Polyfill_HttpContent.cs index c2df4408..9105beb0 100644 --- a/src/Split/net47/Polyfill_HttpContent.cs +++ b/src/Split/net47/Polyfill_HttpContent.cs @@ -16,6 +16,31 @@ public static Stream ReadAsStream( CancellationToken cancellationToken = default) => target.ReadAsStreamAsync(cancellationToken).GetAwaiter().GetResult(); /// + /// Serializes the HTTP content into a stream of bytes and copies it to the stream object provided as the stream parameter. + /// + public static Task CopyToAsync( + this HttpContent target, + Stream stream, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.CopyToAsync(stream) + .WaitAsync(cancellationToken); + } + /// + /// Serializes the HTTP content into a stream of bytes and copies it to the stream object provided as the stream parameter. + /// + public static Task CopyToAsync( + this HttpContent target, + Stream stream, + System.Net.TransportContext? context, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.CopyToAsync(stream, context) + .WaitAsync(cancellationToken); + } + /// /// Serializes the HTTP content into a stream. /// public static void CopyTo( @@ -60,5 +85,28 @@ public static Task ReadAsStringAsync( return target.ReadAsStringAsync() .WaitAsync(cancellationToken); } + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync() + .WaitAsync(cancellationToken); + } + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + long maxBufferSize, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync(maxBufferSize) + .WaitAsync(cancellationToken); + } } #endif diff --git a/src/Split/net471/Polyfill_HttpClient.cs b/src/Split/net471/Polyfill_HttpClient.cs index f512269b..4a591775 100644 --- a/src/Split/net471/Polyfill_HttpClient.cs +++ b/src/Split/net471/Polyfill_HttpClient.cs @@ -10,6 +10,40 @@ namespace Polyfills; static partial class Polyfill { /// + /// Sends a PATCH request to a URI designated as a string as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + string? requestUri, + HttpContent? content) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }); + /// + /// Sends a PATCH request as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + Uri? requestUri, + HttpContent? content) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }); + /// + /// Sends a PATCH request with a cancellation token to a URI represented as a string as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + string? requestUri, + HttpContent? content, + CancellationToken cancellationToken) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }, cancellationToken); + /// + /// Sends a PATCH request with a cancellation token as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + Uri? requestUri, + HttpContent? content, + CancellationToken cancellationToken) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }, cancellationToken); + /// /// Sends an HTTP request with the specified request. /// public static HttpResponseMessage Send( diff --git a/src/Split/net471/Polyfill_HttpContent.cs b/src/Split/net471/Polyfill_HttpContent.cs index c2df4408..9105beb0 100644 --- a/src/Split/net471/Polyfill_HttpContent.cs +++ b/src/Split/net471/Polyfill_HttpContent.cs @@ -16,6 +16,31 @@ public static Stream ReadAsStream( CancellationToken cancellationToken = default) => target.ReadAsStreamAsync(cancellationToken).GetAwaiter().GetResult(); /// + /// Serializes the HTTP content into a stream of bytes and copies it to the stream object provided as the stream parameter. + /// + public static Task CopyToAsync( + this HttpContent target, + Stream stream, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.CopyToAsync(stream) + .WaitAsync(cancellationToken); + } + /// + /// Serializes the HTTP content into a stream of bytes and copies it to the stream object provided as the stream parameter. + /// + public static Task CopyToAsync( + this HttpContent target, + Stream stream, + System.Net.TransportContext? context, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.CopyToAsync(stream, context) + .WaitAsync(cancellationToken); + } + /// /// Serializes the HTTP content into a stream. /// public static void CopyTo( @@ -60,5 +85,28 @@ public static Task ReadAsStringAsync( return target.ReadAsStringAsync() .WaitAsync(cancellationToken); } + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync() + .WaitAsync(cancellationToken); + } + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + long maxBufferSize, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync(maxBufferSize) + .WaitAsync(cancellationToken); + } } #endif diff --git a/src/Split/net472/Polyfill_HttpClient.cs b/src/Split/net472/Polyfill_HttpClient.cs index f512269b..4a591775 100644 --- a/src/Split/net472/Polyfill_HttpClient.cs +++ b/src/Split/net472/Polyfill_HttpClient.cs @@ -10,6 +10,40 @@ namespace Polyfills; static partial class Polyfill { /// + /// Sends a PATCH request to a URI designated as a string as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + string? requestUri, + HttpContent? content) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }); + /// + /// Sends a PATCH request as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + Uri? requestUri, + HttpContent? content) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }); + /// + /// Sends a PATCH request with a cancellation token to a URI represented as a string as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + string? requestUri, + HttpContent? content, + CancellationToken cancellationToken) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }, cancellationToken); + /// + /// Sends a PATCH request with a cancellation token as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + Uri? requestUri, + HttpContent? content, + CancellationToken cancellationToken) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }, cancellationToken); + /// /// Sends an HTTP request with the specified request. /// public static HttpResponseMessage Send( diff --git a/src/Split/net472/Polyfill_HttpContent.cs b/src/Split/net472/Polyfill_HttpContent.cs index c2df4408..9105beb0 100644 --- a/src/Split/net472/Polyfill_HttpContent.cs +++ b/src/Split/net472/Polyfill_HttpContent.cs @@ -16,6 +16,31 @@ public static Stream ReadAsStream( CancellationToken cancellationToken = default) => target.ReadAsStreamAsync(cancellationToken).GetAwaiter().GetResult(); /// + /// Serializes the HTTP content into a stream of bytes and copies it to the stream object provided as the stream parameter. + /// + public static Task CopyToAsync( + this HttpContent target, + Stream stream, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.CopyToAsync(stream) + .WaitAsync(cancellationToken); + } + /// + /// Serializes the HTTP content into a stream of bytes and copies it to the stream object provided as the stream parameter. + /// + public static Task CopyToAsync( + this HttpContent target, + Stream stream, + System.Net.TransportContext? context, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.CopyToAsync(stream, context) + .WaitAsync(cancellationToken); + } + /// /// Serializes the HTTP content into a stream. /// public static void CopyTo( @@ -60,5 +85,28 @@ public static Task ReadAsStringAsync( return target.ReadAsStringAsync() .WaitAsync(cancellationToken); } + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync() + .WaitAsync(cancellationToken); + } + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + long maxBufferSize, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync(maxBufferSize) + .WaitAsync(cancellationToken); + } } #endif diff --git a/src/Split/net48/Polyfill_HttpClient.cs b/src/Split/net48/Polyfill_HttpClient.cs index f512269b..4a591775 100644 --- a/src/Split/net48/Polyfill_HttpClient.cs +++ b/src/Split/net48/Polyfill_HttpClient.cs @@ -10,6 +10,40 @@ namespace Polyfills; static partial class Polyfill { /// + /// Sends a PATCH request to a URI designated as a string as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + string? requestUri, + HttpContent? content) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }); + /// + /// Sends a PATCH request as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + Uri? requestUri, + HttpContent? content) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }); + /// + /// Sends a PATCH request with a cancellation token to a URI represented as a string as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + string? requestUri, + HttpContent? content, + CancellationToken cancellationToken) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }, cancellationToken); + /// + /// Sends a PATCH request with a cancellation token as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + Uri? requestUri, + HttpContent? content, + CancellationToken cancellationToken) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }, cancellationToken); + /// /// Sends an HTTP request with the specified request. /// public static HttpResponseMessage Send( diff --git a/src/Split/net48/Polyfill_HttpContent.cs b/src/Split/net48/Polyfill_HttpContent.cs index c2df4408..9105beb0 100644 --- a/src/Split/net48/Polyfill_HttpContent.cs +++ b/src/Split/net48/Polyfill_HttpContent.cs @@ -16,6 +16,31 @@ public static Stream ReadAsStream( CancellationToken cancellationToken = default) => target.ReadAsStreamAsync(cancellationToken).GetAwaiter().GetResult(); /// + /// Serializes the HTTP content into a stream of bytes and copies it to the stream object provided as the stream parameter. + /// + public static Task CopyToAsync( + this HttpContent target, + Stream stream, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.CopyToAsync(stream) + .WaitAsync(cancellationToken); + } + /// + /// Serializes the HTTP content into a stream of bytes and copies it to the stream object provided as the stream parameter. + /// + public static Task CopyToAsync( + this HttpContent target, + Stream stream, + System.Net.TransportContext? context, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.CopyToAsync(stream, context) + .WaitAsync(cancellationToken); + } + /// /// Serializes the HTTP content into a stream. /// public static void CopyTo( @@ -60,5 +85,28 @@ public static Task ReadAsStringAsync( return target.ReadAsStringAsync() .WaitAsync(cancellationToken); } + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync() + .WaitAsync(cancellationToken); + } + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + long maxBufferSize, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync(maxBufferSize) + .WaitAsync(cancellationToken); + } } #endif diff --git a/src/Split/net481/Polyfill_HttpClient.cs b/src/Split/net481/Polyfill_HttpClient.cs index f512269b..4a591775 100644 --- a/src/Split/net481/Polyfill_HttpClient.cs +++ b/src/Split/net481/Polyfill_HttpClient.cs @@ -10,6 +10,40 @@ namespace Polyfills; static partial class Polyfill { /// + /// Sends a PATCH request to a URI designated as a string as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + string? requestUri, + HttpContent? content) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }); + /// + /// Sends a PATCH request as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + Uri? requestUri, + HttpContent? content) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }); + /// + /// Sends a PATCH request with a cancellation token to a URI represented as a string as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + string? requestUri, + HttpContent? content, + CancellationToken cancellationToken) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }, cancellationToken); + /// + /// Sends a PATCH request with a cancellation token as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + Uri? requestUri, + HttpContent? content, + CancellationToken cancellationToken) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }, cancellationToken); + /// /// Sends an HTTP request with the specified request. /// public static HttpResponseMessage Send( diff --git a/src/Split/net481/Polyfill_HttpContent.cs b/src/Split/net481/Polyfill_HttpContent.cs index c2df4408..9105beb0 100644 --- a/src/Split/net481/Polyfill_HttpContent.cs +++ b/src/Split/net481/Polyfill_HttpContent.cs @@ -16,6 +16,31 @@ public static Stream ReadAsStream( CancellationToken cancellationToken = default) => target.ReadAsStreamAsync(cancellationToken).GetAwaiter().GetResult(); /// + /// Serializes the HTTP content into a stream of bytes and copies it to the stream object provided as the stream parameter. + /// + public static Task CopyToAsync( + this HttpContent target, + Stream stream, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.CopyToAsync(stream) + .WaitAsync(cancellationToken); + } + /// + /// Serializes the HTTP content into a stream of bytes and copies it to the stream object provided as the stream parameter. + /// + public static Task CopyToAsync( + this HttpContent target, + Stream stream, + System.Net.TransportContext? context, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.CopyToAsync(stream, context) + .WaitAsync(cancellationToken); + } + /// /// Serializes the HTTP content into a stream. /// public static void CopyTo( @@ -60,5 +85,28 @@ public static Task ReadAsStringAsync( return target.ReadAsStringAsync() .WaitAsync(cancellationToken); } + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync() + .WaitAsync(cancellationToken); + } + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + long maxBufferSize, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync(maxBufferSize) + .WaitAsync(cancellationToken); + } } #endif diff --git a/src/Split/net5.0/Polyfill_HttpContent.cs b/src/Split/net5.0/Polyfill_HttpContent.cs index 267da168..1dd0955a 100644 --- a/src/Split/net5.0/Polyfill_HttpContent.cs +++ b/src/Split/net5.0/Polyfill_HttpContent.cs @@ -15,5 +15,28 @@ public static Stream ReadAsStream( this HttpContent target, CancellationToken cancellationToken = default) => target.ReadAsStreamAsync(cancellationToken).GetAwaiter().GetResult(); + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync() + .WaitAsync(cancellationToken); + } + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + long maxBufferSize, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync(maxBufferSize) + .WaitAsync(cancellationToken); + } } #endif diff --git a/src/Split/net6.0/Polyfill_HttpContent.cs b/src/Split/net6.0/Polyfill_HttpContent.cs new file mode 100644 index 00000000..bda5fb64 --- /dev/null +++ b/src/Split/net6.0/Polyfill_HttpContent.cs @@ -0,0 +1,35 @@ +// +#pragma warning disable +#if FeatureHttp +namespace Polyfills; +using System.IO; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; +static partial class Polyfill +{ + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync() + .WaitAsync(cancellationToken); + } + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + long maxBufferSize, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync(maxBufferSize) + .WaitAsync(cancellationToken); + } +} +#endif diff --git a/src/Split/net7.0/Polyfill_HttpContent.cs b/src/Split/net7.0/Polyfill_HttpContent.cs new file mode 100644 index 00000000..bda5fb64 --- /dev/null +++ b/src/Split/net7.0/Polyfill_HttpContent.cs @@ -0,0 +1,35 @@ +// +#pragma warning disable +#if FeatureHttp +namespace Polyfills; +using System.IO; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; +static partial class Polyfill +{ + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync() + .WaitAsync(cancellationToken); + } + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + long maxBufferSize, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync(maxBufferSize) + .WaitAsync(cancellationToken); + } +} +#endif diff --git a/src/Split/net8.0/Polyfill_HttpContent.cs b/src/Split/net8.0/Polyfill_HttpContent.cs new file mode 100644 index 00000000..bda5fb64 --- /dev/null +++ b/src/Split/net8.0/Polyfill_HttpContent.cs @@ -0,0 +1,35 @@ +// +#pragma warning disable +#if FeatureHttp +namespace Polyfills; +using System.IO; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; +static partial class Polyfill +{ + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync() + .WaitAsync(cancellationToken); + } + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + long maxBufferSize, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync(maxBufferSize) + .WaitAsync(cancellationToken); + } +} +#endif diff --git a/src/Split/netcoreapp2.0/Polyfill_HttpClient.cs b/src/Split/netcoreapp2.0/Polyfill_HttpClient.cs index f512269b..4a591775 100644 --- a/src/Split/netcoreapp2.0/Polyfill_HttpClient.cs +++ b/src/Split/netcoreapp2.0/Polyfill_HttpClient.cs @@ -10,6 +10,40 @@ namespace Polyfills; static partial class Polyfill { /// + /// Sends a PATCH request to a URI designated as a string as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + string? requestUri, + HttpContent? content) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }); + /// + /// Sends a PATCH request as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + Uri? requestUri, + HttpContent? content) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }); + /// + /// Sends a PATCH request with a cancellation token to a URI represented as a string as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + string? requestUri, + HttpContent? content, + CancellationToken cancellationToken) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }, cancellationToken); + /// + /// Sends a PATCH request with a cancellation token as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + Uri? requestUri, + HttpContent? content, + CancellationToken cancellationToken) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }, cancellationToken); + /// /// Sends an HTTP request with the specified request. /// public static HttpResponseMessage Send( diff --git a/src/Split/netcoreapp2.0/Polyfill_HttpContent.cs b/src/Split/netcoreapp2.0/Polyfill_HttpContent.cs index c2df4408..9105beb0 100644 --- a/src/Split/netcoreapp2.0/Polyfill_HttpContent.cs +++ b/src/Split/netcoreapp2.0/Polyfill_HttpContent.cs @@ -16,6 +16,31 @@ public static Stream ReadAsStream( CancellationToken cancellationToken = default) => target.ReadAsStreamAsync(cancellationToken).GetAwaiter().GetResult(); /// + /// Serializes the HTTP content into a stream of bytes and copies it to the stream object provided as the stream parameter. + /// + public static Task CopyToAsync( + this HttpContent target, + Stream stream, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.CopyToAsync(stream) + .WaitAsync(cancellationToken); + } + /// + /// Serializes the HTTP content into a stream of bytes and copies it to the stream object provided as the stream parameter. + /// + public static Task CopyToAsync( + this HttpContent target, + Stream stream, + System.Net.TransportContext? context, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.CopyToAsync(stream, context) + .WaitAsync(cancellationToken); + } + /// /// Serializes the HTTP content into a stream. /// public static void CopyTo( @@ -60,5 +85,28 @@ public static Task ReadAsStringAsync( return target.ReadAsStringAsync() .WaitAsync(cancellationToken); } + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync() + .WaitAsync(cancellationToken); + } + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + long maxBufferSize, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync(maxBufferSize) + .WaitAsync(cancellationToken); + } } #endif diff --git a/src/Split/netcoreapp2.1/Polyfill_HttpContent.cs b/src/Split/netcoreapp2.1/Polyfill_HttpContent.cs index c2df4408..9105beb0 100644 --- a/src/Split/netcoreapp2.1/Polyfill_HttpContent.cs +++ b/src/Split/netcoreapp2.1/Polyfill_HttpContent.cs @@ -16,6 +16,31 @@ public static Stream ReadAsStream( CancellationToken cancellationToken = default) => target.ReadAsStreamAsync(cancellationToken).GetAwaiter().GetResult(); /// + /// Serializes the HTTP content into a stream of bytes and copies it to the stream object provided as the stream parameter. + /// + public static Task CopyToAsync( + this HttpContent target, + Stream stream, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.CopyToAsync(stream) + .WaitAsync(cancellationToken); + } + /// + /// Serializes the HTTP content into a stream of bytes and copies it to the stream object provided as the stream parameter. + /// + public static Task CopyToAsync( + this HttpContent target, + Stream stream, + System.Net.TransportContext? context, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.CopyToAsync(stream, context) + .WaitAsync(cancellationToken); + } + /// /// Serializes the HTTP content into a stream. /// public static void CopyTo( @@ -60,5 +85,28 @@ public static Task ReadAsStringAsync( return target.ReadAsStringAsync() .WaitAsync(cancellationToken); } + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync() + .WaitAsync(cancellationToken); + } + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + long maxBufferSize, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync(maxBufferSize) + .WaitAsync(cancellationToken); + } } #endif diff --git a/src/Split/netcoreapp2.2/Polyfill_HttpContent.cs b/src/Split/netcoreapp2.2/Polyfill_HttpContent.cs index c2df4408..9105beb0 100644 --- a/src/Split/netcoreapp2.2/Polyfill_HttpContent.cs +++ b/src/Split/netcoreapp2.2/Polyfill_HttpContent.cs @@ -16,6 +16,31 @@ public static Stream ReadAsStream( CancellationToken cancellationToken = default) => target.ReadAsStreamAsync(cancellationToken).GetAwaiter().GetResult(); /// + /// Serializes the HTTP content into a stream of bytes and copies it to the stream object provided as the stream parameter. + /// + public static Task CopyToAsync( + this HttpContent target, + Stream stream, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.CopyToAsync(stream) + .WaitAsync(cancellationToken); + } + /// + /// Serializes the HTTP content into a stream of bytes and copies it to the stream object provided as the stream parameter. + /// + public static Task CopyToAsync( + this HttpContent target, + Stream stream, + System.Net.TransportContext? context, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.CopyToAsync(stream, context) + .WaitAsync(cancellationToken); + } + /// /// Serializes the HTTP content into a stream. /// public static void CopyTo( @@ -60,5 +85,28 @@ public static Task ReadAsStringAsync( return target.ReadAsStringAsync() .WaitAsync(cancellationToken); } + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync() + .WaitAsync(cancellationToken); + } + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + long maxBufferSize, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync(maxBufferSize) + .WaitAsync(cancellationToken); + } } #endif diff --git a/src/Split/netcoreapp3.0/Polyfill_HttpContent.cs b/src/Split/netcoreapp3.0/Polyfill_HttpContent.cs index c2df4408..9105beb0 100644 --- a/src/Split/netcoreapp3.0/Polyfill_HttpContent.cs +++ b/src/Split/netcoreapp3.0/Polyfill_HttpContent.cs @@ -16,6 +16,31 @@ public static Stream ReadAsStream( CancellationToken cancellationToken = default) => target.ReadAsStreamAsync(cancellationToken).GetAwaiter().GetResult(); /// + /// Serializes the HTTP content into a stream of bytes and copies it to the stream object provided as the stream parameter. + /// + public static Task CopyToAsync( + this HttpContent target, + Stream stream, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.CopyToAsync(stream) + .WaitAsync(cancellationToken); + } + /// + /// Serializes the HTTP content into a stream of bytes and copies it to the stream object provided as the stream parameter. + /// + public static Task CopyToAsync( + this HttpContent target, + Stream stream, + System.Net.TransportContext? context, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.CopyToAsync(stream, context) + .WaitAsync(cancellationToken); + } + /// /// Serializes the HTTP content into a stream. /// public static void CopyTo( @@ -60,5 +85,28 @@ public static Task ReadAsStringAsync( return target.ReadAsStringAsync() .WaitAsync(cancellationToken); } + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync() + .WaitAsync(cancellationToken); + } + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + long maxBufferSize, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync(maxBufferSize) + .WaitAsync(cancellationToken); + } } #endif diff --git a/src/Split/netcoreapp3.1/Polyfill_HttpContent.cs b/src/Split/netcoreapp3.1/Polyfill_HttpContent.cs index c2df4408..9105beb0 100644 --- a/src/Split/netcoreapp3.1/Polyfill_HttpContent.cs +++ b/src/Split/netcoreapp3.1/Polyfill_HttpContent.cs @@ -16,6 +16,31 @@ public static Stream ReadAsStream( CancellationToken cancellationToken = default) => target.ReadAsStreamAsync(cancellationToken).GetAwaiter().GetResult(); /// + /// Serializes the HTTP content into a stream of bytes and copies it to the stream object provided as the stream parameter. + /// + public static Task CopyToAsync( + this HttpContent target, + Stream stream, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.CopyToAsync(stream) + .WaitAsync(cancellationToken); + } + /// + /// Serializes the HTTP content into a stream of bytes and copies it to the stream object provided as the stream parameter. + /// + public static Task CopyToAsync( + this HttpContent target, + Stream stream, + System.Net.TransportContext? context, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.CopyToAsync(stream, context) + .WaitAsync(cancellationToken); + } + /// /// Serializes the HTTP content into a stream. /// public static void CopyTo( @@ -60,5 +85,28 @@ public static Task ReadAsStringAsync( return target.ReadAsStringAsync() .WaitAsync(cancellationToken); } + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync() + .WaitAsync(cancellationToken); + } + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + long maxBufferSize, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync(maxBufferSize) + .WaitAsync(cancellationToken); + } } #endif diff --git a/src/Split/netstandard2.0/Polyfill_HttpClient.cs b/src/Split/netstandard2.0/Polyfill_HttpClient.cs index f512269b..4a591775 100644 --- a/src/Split/netstandard2.0/Polyfill_HttpClient.cs +++ b/src/Split/netstandard2.0/Polyfill_HttpClient.cs @@ -10,6 +10,40 @@ namespace Polyfills; static partial class Polyfill { /// + /// Sends a PATCH request to a URI designated as a string as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + string? requestUri, + HttpContent? content) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }); + /// + /// Sends a PATCH request as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + Uri? requestUri, + HttpContent? content) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }); + /// + /// Sends a PATCH request with a cancellation token to a URI represented as a string as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + string? requestUri, + HttpContent? content, + CancellationToken cancellationToken) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }, cancellationToken); + /// + /// Sends a PATCH request with a cancellation token as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + Uri? requestUri, + HttpContent? content, + CancellationToken cancellationToken) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }, cancellationToken); + /// /// Sends an HTTP request with the specified request. /// public static HttpResponseMessage Send( diff --git a/src/Split/netstandard2.0/Polyfill_HttpContent.cs b/src/Split/netstandard2.0/Polyfill_HttpContent.cs index c2df4408..9105beb0 100644 --- a/src/Split/netstandard2.0/Polyfill_HttpContent.cs +++ b/src/Split/netstandard2.0/Polyfill_HttpContent.cs @@ -16,6 +16,31 @@ public static Stream ReadAsStream( CancellationToken cancellationToken = default) => target.ReadAsStreamAsync(cancellationToken).GetAwaiter().GetResult(); /// + /// Serializes the HTTP content into a stream of bytes and copies it to the stream object provided as the stream parameter. + /// + public static Task CopyToAsync( + this HttpContent target, + Stream stream, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.CopyToAsync(stream) + .WaitAsync(cancellationToken); + } + /// + /// Serializes the HTTP content into a stream of bytes and copies it to the stream object provided as the stream parameter. + /// + public static Task CopyToAsync( + this HttpContent target, + Stream stream, + System.Net.TransportContext? context, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.CopyToAsync(stream, context) + .WaitAsync(cancellationToken); + } + /// /// Serializes the HTTP content into a stream. /// public static void CopyTo( @@ -60,5 +85,28 @@ public static Task ReadAsStringAsync( return target.ReadAsStringAsync() .WaitAsync(cancellationToken); } + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync() + .WaitAsync(cancellationToken); + } + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + long maxBufferSize, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync(maxBufferSize) + .WaitAsync(cancellationToken); + } } #endif diff --git a/src/Split/netstandard2.1/Polyfill_HttpContent.cs b/src/Split/netstandard2.1/Polyfill_HttpContent.cs index c2df4408..9105beb0 100644 --- a/src/Split/netstandard2.1/Polyfill_HttpContent.cs +++ b/src/Split/netstandard2.1/Polyfill_HttpContent.cs @@ -16,6 +16,31 @@ public static Stream ReadAsStream( CancellationToken cancellationToken = default) => target.ReadAsStreamAsync(cancellationToken).GetAwaiter().GetResult(); /// + /// Serializes the HTTP content into a stream of bytes and copies it to the stream object provided as the stream parameter. + /// + public static Task CopyToAsync( + this HttpContent target, + Stream stream, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.CopyToAsync(stream) + .WaitAsync(cancellationToken); + } + /// + /// Serializes the HTTP content into a stream of bytes and copies it to the stream object provided as the stream parameter. + /// + public static Task CopyToAsync( + this HttpContent target, + Stream stream, + System.Net.TransportContext? context, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.CopyToAsync(stream, context) + .WaitAsync(cancellationToken); + } + /// /// Serializes the HTTP content into a stream. /// public static void CopyTo( @@ -60,5 +85,28 @@ public static Task ReadAsStringAsync( return target.ReadAsStringAsync() .WaitAsync(cancellationToken); } + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync() + .WaitAsync(cancellationToken); + } + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + long maxBufferSize, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync(maxBufferSize) + .WaitAsync(cancellationToken); + } } #endif diff --git a/src/Split/uap10.0/Polyfill_HttpClient.cs b/src/Split/uap10.0/Polyfill_HttpClient.cs index f512269b..4a591775 100644 --- a/src/Split/uap10.0/Polyfill_HttpClient.cs +++ b/src/Split/uap10.0/Polyfill_HttpClient.cs @@ -10,6 +10,40 @@ namespace Polyfills; static partial class Polyfill { /// + /// Sends a PATCH request to a URI designated as a string as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + string? requestUri, + HttpContent? content) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }); + /// + /// Sends a PATCH request as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + Uri? requestUri, + HttpContent? content) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }); + /// + /// Sends a PATCH request with a cancellation token to a URI represented as a string as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + string? requestUri, + HttpContent? content, + CancellationToken cancellationToken) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }, cancellationToken); + /// + /// Sends a PATCH request with a cancellation token as an asynchronous operation. + /// + public static Task PatchAsync( + this HttpClient target, + Uri? requestUri, + HttpContent? content, + CancellationToken cancellationToken) => + target.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content }, cancellationToken); + /// /// Sends an HTTP request with the specified request. /// public static HttpResponseMessage Send( diff --git a/src/Split/uap10.0/Polyfill_HttpContent.cs b/src/Split/uap10.0/Polyfill_HttpContent.cs index c2df4408..9105beb0 100644 --- a/src/Split/uap10.0/Polyfill_HttpContent.cs +++ b/src/Split/uap10.0/Polyfill_HttpContent.cs @@ -16,6 +16,31 @@ public static Stream ReadAsStream( CancellationToken cancellationToken = default) => target.ReadAsStreamAsync(cancellationToken).GetAwaiter().GetResult(); /// + /// Serializes the HTTP content into a stream of bytes and copies it to the stream object provided as the stream parameter. + /// + public static Task CopyToAsync( + this HttpContent target, + Stream stream, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.CopyToAsync(stream) + .WaitAsync(cancellationToken); + } + /// + /// Serializes the HTTP content into a stream of bytes and copies it to the stream object provided as the stream parameter. + /// + public static Task CopyToAsync( + this HttpContent target, + Stream stream, + System.Net.TransportContext? context, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.CopyToAsync(stream, context) + .WaitAsync(cancellationToken); + } + /// /// Serializes the HTTP content into a stream. /// public static void CopyTo( @@ -60,5 +85,28 @@ public static Task ReadAsStringAsync( return target.ReadAsStringAsync() .WaitAsync(cancellationToken); } + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync() + .WaitAsync(cancellationToken); + } + /// + /// Serialize the HTTP content to a memory buffer as an asynchronous operation. + /// + public static Task LoadIntoBufferAsync( + this HttpContent target, + long maxBufferSize, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return target.LoadIntoBufferAsync(maxBufferSize) + .WaitAsync(cancellationToken); + } } #endif diff --git a/src/Tests/PolyfillTests_HttpClient.cs b/src/Tests/PolyfillTests_HttpClient.cs index 189ccc1c..592406f6 100644 --- a/src/Tests/PolyfillTests_HttpClient.cs +++ b/src/Tests/PolyfillTests_HttpClient.cs @@ -125,6 +125,52 @@ public async Task HttpClientSendWithCompletionOptionAndCancellationToken_Cancell } } + [Test] + public async Task HttpClientPatchAsync_String() + { + using var httpClient = new HttpClient(new FakeHttpMessageHandler(), true); + using var content = new StringContent("patch data"); + + using var response = await httpClient.PatchAsync("https://example.com", content); + + await Assert.That(response.StatusCode).IsEqualTo(HttpStatusCode.OK); + } + + [Test] + public async Task HttpClientPatchAsync_Uri() + { + using var httpClient = new HttpClient(new FakeHttpMessageHandler(), true); + using var content = new StringContent("patch data"); + + using var response = await httpClient.PatchAsync(new Uri("https://example.com"), content); + + await Assert.That(response.StatusCode).IsEqualTo(HttpStatusCode.OK); + } + + [Test] + public async Task HttpClientPatchAsync_String_WithCancellationToken() + { + var cancel = new Cancel(); + using var httpClient = new HttpClient(new FakeHttpMessageHandler(), true); + using var content = new StringContent("patch data"); + + using var response = await httpClient.PatchAsync("https://example.com", content, cancel); + + await Assert.That(response.StatusCode).IsEqualTo(HttpStatusCode.OK); + } + + [Test] + public async Task HttpClientPatchAsync_Uri_WithCancellationToken() + { + var cancel = new Cancel(); + using var httpClient = new HttpClient(new FakeHttpMessageHandler(), true); + using var content = new StringContent("patch data"); + + using var response = await httpClient.PatchAsync(new Uri("https://example.com"), content, cancel); + + await Assert.That(response.StatusCode).IsEqualTo(HttpStatusCode.OK); + } + [Test] public async Task HttpClientGetStreamAsync_Positive() { diff --git a/src/Tests/PolyfillTests_HttpContent.cs b/src/Tests/PolyfillTests_HttpContent.cs index 54264af9..492986c1 100644 --- a/src/Tests/PolyfillTests_HttpContent.cs +++ b/src/Tests/PolyfillTests_HttpContent.cs @@ -56,5 +56,41 @@ public async Task HttpContent_ReadAsStreamAsync_WithCancellation() await Assert.That(stream).IsNotNull(); await Assert.That(stream.CanRead).IsTrue(); } + + [Test] + public async Task HttpContent_CopyToAsync_WithCancellation() + { + using var content = new StringContent("test data"); + using var destination = new MemoryStream(); + await content.CopyToAsync(destination, CancellationToken.None); + await Assert.That(destination.Length).IsGreaterThan(0); + } + + [Test] + public async Task HttpContent_CopyToAsync_WithContextAndCancellation() + { + using var content = new StringContent("test data"); + using var destination = new MemoryStream(); + await content.CopyToAsync(destination, null, CancellationToken.None); + await Assert.That(destination.Length).IsGreaterThan(0); + } + + [Test] + public async Task HttpContent_LoadIntoBufferAsync_WithCancellation() + { + using var content = new StringContent("test data"); + await content.LoadIntoBufferAsync(CancellationToken.None); + var result = await content.ReadAsStringAsync(); + await Assert.That(result).IsEqualTo("test data"); + } + + [Test] + public async Task HttpContent_LoadIntoBufferAsync_WithMaxBufferSizeAndCancellation() + { + using var content = new StringContent("test data"); + await content.LoadIntoBufferAsync(1024 * 1024, CancellationToken.None); + var result = await content.ReadAsStringAsync(); + await Assert.That(result).IsEqualTo("test data"); + } } #endif From 076885439dea63782bd6ed20a156475369c5cf11 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Sun, 15 Mar 2026 19:28:53 +1100 Subject: [PATCH 2/3] Update Directory.Build.props --- src/Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 37db08bb..01200dd6 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -2,7 +2,7 @@ CS1591;NETSDK1138;NU1901;NU1902;NU1903;CA1822;CA1847;CA1861;NU1510;NU1608;NU1109 - 9.21.0 + 9.22.0 1.0.0 Polyfill true From 14d8be50376ba88246455e041e15f249909fcdcc Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Sun, 15 Mar 2026 20:00:14 +1100 Subject: [PATCH 3/3] Update Consume.cs --- src/Consume/Consume.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Consume/Consume.cs b/src/Consume/Consume.cs index f4430660..65f4967a 100644 --- a/src/Consume/Consume.cs +++ b/src/Consume/Consume.cs @@ -748,10 +748,10 @@ void HashSet_Methods() #if FeatureHttp void HttpClient_Methods(HttpClient target) { - target.PatchAsync("", null); - target.PatchAsync(new Uri("http://a"), null); - target.PatchAsync("", null, CancellationToken.None); - target.PatchAsync(new Uri("http://a"), null, CancellationToken.None); + target.PatchAsync("", new StringContent("")); + target.PatchAsync(new Uri("http://a"), new StringContent("")); + target.PatchAsync("", new StringContent(""), CancellationToken.None); + target.PatchAsync(new Uri("http://a"), new StringContent(""), CancellationToken.None); target.Send(new HttpRequestMessage()); target.Send(new HttpRequestMessage(), HttpCompletionOption.ResponseContentRead); target.Send(new HttpRequestMessage(), CancellationToken.None);