Skip to content

Add HttpContent.CopyToAsync polyfills with CancellationToken - #149

Merged
Tyrrrz merged 4 commits into
primefrom
copilot/add-polyfills-for-httpcontent-copytoasync
Oct 3, 2026
Merged

Tyrrrz merged 4 commits into
primefrom
copilot/add-polyfills-for-httpcontent-copytoasync

Conversation

Copilot AI commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

HttpContent.CopyToAsync gained two CancellationToken-accepting overloads in .NET 5. The existing HttpContent polyfills covered ReadAsStreamAsync/ReadAsByteArrayAsync/ReadAsStringAsync but not CopyToAsync, leaving no way to pass a cancellation token on older target frameworks.

Polyfills added (PolyShim/Net50/HttpContent.cs)

  • Task CopyToAsync(Stream, CancellationToken)
  • Task CopyToAsync(Stream, TransportContext?, CancellationToken)

Both follow the established pattern for this file: check cancellationToken.ThrowIfCancellationRequested() up front, then delegate to the native non-cancellable overload.

await content.CopyToAsync(stream, cancellationToken);
await content.CopyToAsync(stream, transportContext, cancellationToken);

The other two overloads documented on the CopyToAsync API page — CopyToAsync(Stream) and CopyToAsync(Stream, TransportContext?) — already exist on every supported target framework via the abstract HttpContent base class, so they don't require a polyfill.

Other changes

  • Added tests in PolyShim.Tests/Net50/HttpClientTests.cs covering both new overloads, including cancellation behavior.
  • Regenerated Signatures.md to reflect the new polyfills.

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>

@Tyrrrz Tyrrrz left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread PolyShim.Tests/Net50/HttpClientTests.cs Outdated
…c tests

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Copilot AI requested a review from Tyrrrz October 3, 2026 12:17
@Tyrrrz
Tyrrrz marked this pull request as ready for review October 3, 2026 12:23
Copilot AI balanced review requested due to automatic review settings October 3, 2026 12:23
@Tyrrrz

Tyrrrz commented Oct 3, 2026

Copy link
Copy Markdown
Owner

@copilot resolve merge conflicts by merging latest prime and regenerating signatures

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The success tests call existing instance overloads rather than the new polyfills.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds .NET 5 HttpContent.CopyToAsync cancellation-token polyfills for older targets.

Changes:

  • Adds both cancellation-aware overloads.
  • Adds success and cancellation tests.
  • Regenerates API signatures.
File Description
Signatures.md Documents the new overloads.
PolyShim/​Net50/​HttpContent.cs Implements both polyfills.
PolyShim.Tests/​Net50/​HttpClientTests.cs Adds copy and cancellation tests.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread PolyShim.Tests/Net50/HttpClientTests.cs Outdated
Copilot AI and others added 2 commits October 3, 2026 12:27
…s-for-httpcontent-copytoasync

# Conflicts:
#	Signatures.md

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

@copilot resolve merge conflicts by merging latest prime and regenerating signatures

Merged the latest prime branch and regenerated Signatures.md. Merge commit: 39bdf3d.

Copilot AI requested a review from Tyrrrz October 3, 2026 12:30
@codecov

codecov Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.73684% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.18%. Comparing base (9930c2b) to head (8b0e3e5).

Files with missing lines Patch % Lines
PolyShim/Net50/HttpContent.cs 66.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            prime     #149      +/-   ##
==========================================
+ Coverage   88.12%   88.18%   +0.05%     
==========================================
  Files         347      347              
  Lines        7773     7811      +38     
  Branches      557      557              
==========================================
+ Hits         6850     6888      +38     
  Misses        754      754              
  Partials      169      169              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Tyrrrz
Tyrrrz merged commit 415e710 into prime Oct 3, 2026
7 checks passed
@Tyrrrz
Tyrrrz deleted the copilot/add-polyfills-for-httpcontent-copytoasync branch October 3, 2026 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants