Skip to content

fix: disambiguate case-differing parameters, preserve ContentLength header, and surface buffering exceptions - #2360

Merged
glennawatson merged 11 commits into
mainfrom
fix/open-issues-2356-2357-2359
Oct 17, 2026
Merged

glennawatson merged 11 commits into
mainfrom
fix/open-issues-2356-2357-2359

Conversation

@glennawatson

@glennawatson glennawatson commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes three bugs across route/query parameter binding, IApiResponse.ContentHeaders lifetime, and response body buffering error handling, fixes the .NET 11 RC2 Native AOT smoke publish, and updates non-pinned NuGet dependencies to their latest versions.

  • Disambiguates route and query parameters that share the same case-insensitive URL name so non-[Query] parameters and exact-case matches bind the route placeholder while sibling parameters remain query parameters in both the source generator and reflection request builders.
  • Preserves IApiResponse.ContentHeaders.ContentLength across HttpContent buffering and disposal so reading ContentLength after response disposal returns null instead of throwing ObjectDisposedException when the response omitted an explicit Content-Length header.
  • Surfaces the original transport exception when response body buffering fails mid-stream and subsequent content deserialization fails because the underlying response stream was already consumed.
  • Sets PublishDocumentationFile=false when PublishAot=true so .NET 11 RC2's UseOptimizedPublish (which skips CopyFilesToOutputDirectory) does not fail looking for @(FinalDocFile) in bin/, and updates non-pinned NuGet packages across src/.

Why

Breaking changes

None.

How this was verified

Added unit and live request-building tests covering case-differing route/query parameter combinations (including source-generator and reflection parity), ContentHeaders.ContentLength access after response disposal, and mid-stream response buffering failures for both direct and ApiResponse<T> return shapes; verified Native AOT publishing for Refit.NativeAotSmoke and NativeClient.

Notes for the reviewer

Checklist

  • I have read the Contribute guide
  • The PR title follows Conventional Commits
  • Tests cover this change, or the summary says why they do not
  • New or changed public API has XML documentation

- Disambiguate route and query parameters when sibling parameters share the same case-insensitive URL name (#2356)
- Preserve uncomputed ContentHeaders.ContentLength across HttpContent buffering and disposal (#2357)
- Rethrow original transport exception when response buffering fails on a single-read stream and deserialization subsequently throws (#2359)

Fixes #2356
Fixes #2357
Fixes #2359
@glennawatson glennawatson changed the title fix: resolve open issues #2356, #2357, and #2359 fix: disambiguate case-differing parameters, preserve ContentLength header, and surface buffering exceptions Oct 16, 2026
@codecov

codecov Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.97%. Comparing base (970bf3e) to head (0b6c8e0).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #2360    +/-   ##
========================================
  Coverage   99.97%   99.97%            
========================================
  Files         219      219            
  Lines       11784    11903   +119     
  Branches     2262     2302    +40     
========================================
+ Hits        11781    11900   +119     
  Misses          3        3            

☔ 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.

…lish

- Disable PublishDocumentationFile when PublishAot is true so .NET 11 RC2 UseOptimizedPublish does not fail copying @(FinalDocFile) from bin/
- Update non-pinned NuGet packages to latest versions and await NUnit 5.0.0 Assert.ThrowsAsync in documentation examples

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.

🟡 Changes recommended

Route-candidate eligibility, whitespace-format parity, and cancellation propagation remain unresolved.

3 open issues
What changed in this PR

Addresses route/query binding, response-header lifetime, and buffering-error reporting in Refit. Also updates dependencies and Native AOT publishing configuration.

Changes:

  • Adds case-sensitive route-candidate ranking and generated/reflection parity tests.
  • Preserves content-length headers and original buffering exceptions, with regression coverage.
  • Updates NuGet dependencies, NUnit examples, and AOT documentation publishing.
File Description
src/​tests/​Refit.Tests/​ResponseTests.ErrorHandling.cs Tests missing content length after disposal.
src/​tests/​Refit.Tests/​GeneratedRequestRunnerTests.ResponseErrorHandling.cs Tests buffering-error propagation.
src/​tests/​Refit.Tests/​GeneratedRequestRunnerTests.cs Adds single-read failing content fixture.
src/​tests/​Refit.Tests/​ApiResponseTests.cs Tests header preservation across disposal.
src/​tests/​Refit.GeneratorTests/​QueryRequestBuildingLiveTests.Helpers.cs Adds route/query collision scenarios.
src/​tests/​Refit.GeneratorTests/​QueryRequestBuildingLiveTests.cs Tests generated/reflection binding parity.
src/​tests/​Refit.GeneratorTests/​LiveQueryApi.cs Declares matching parity-test endpoints.
src/​Refit/​RequestExecutionHelpers.cs Preserves headers and buffering failures.
src/​Refit/​ApiResponse{T}.cs Preserves content length before disposal.
src/​Refit/​ApiException.cs Preserves content length before error-body reads.
src/​Refit.Reflection/​RestMethodInfoInternal.ParameterBinding.cs Ranks competing reflection route parameters.
src/​InterfaceStubGenerator.Shared/​Parser.Request.Parameters.cs Disambiguates generated route bindings.
src/​examples/​Documentation/​TestingFrameworks/​XUnit/​Directory.Packages.props Updates xUnit.
src/​examples/​Documentation/​TestingFrameworks/​NUnit/​NetworkConditionsTests.cs Awaits asynchronous exception assertion.
src/​examples/​Documentation/​TestingFrameworks/​NUnit/​ErrorHandlingTests.cs Awaits asynchronous exception assertion.
src/​examples/​Documentation/​TestingFrameworks/​NUnit/​Directory.Packages.props Updates NUnit and adapter.
src/​examples/​Documentation/​TestingFrameworks/​MSTest/​Directory.Packages.props Updates MSTest packages.
src/​Directory.Packages.props Updates shared dependencies.
src/​Directory.Build.targets Disables documentation publishing for AOT.

Review effort: Balanced

Comment thread src/Refit/RequestExecutionHelpers.cs Resolved

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.

🟡 Changes recommended

Mixed ordinary/catch-all placeholders still cause overlapping generated replacements and incorrect reflection bindings.

1 open issue
3 resolved since last review

Review effort: Balanced

@glennawatson
glennawatson requested a balanced review from Copilot October 17, 2026 00:31

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.

Comment thread src/Refit/RequestExecutionHelpers.cs Resolved
Comment thread src/Refit/RequestExecutionHelpers.cs Resolved
@glennawatson
glennawatson requested a balanced review from Copilot October 17, 2026 01:42

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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

8 open issues
4 resolved since last review

Review effort: Lite

Comment thread src/Refit.slnx Resolved
Comment thread src/Refit/RequestExecutionHelpers.cs Resolved
Comment thread src/Refit/RequestExecutionHelpers.cs Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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.

🔵 Needs a closer look

An unresolved route-binding defect and broad dependency and publishing changes require correction and human validation.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Prevent non-query bonus from overriding placeholder reservations

src/​InterfaceStubGenerator.Shared/​Parser.Request.Parameters.cs:248

The non-query bonus can override reservation for another placeholder in both this method and RestMethodInfoInternal.GetRouteCandidateRank. For /accounts/{id}/positions/{ID} with (int id, [Query] int ID) and values (10, 20), id scores 3 for {ID} while the exact match scores 2. Both placeholders therefore use id, producing /accounts/10/positions/10?ID=20 instead of /accounts/10/positions/20. Swapping which parameter has [Query] causes the opposite misbinding. In both implementations, return claimedByOtherPlaceholderRank before applying the non-query bonus when caseRank has that value. Add live parity tests covering both mixed-annotation arrangements; the existing both-bare-query and formatted-query cases do not cover this.

5 resolved since last review

Review effort: Balanced

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.

🔵 Needs a closer look

An unresolved routing defect and broad cross-target dependency changes require correction and final human validation.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Prevent fallback binding from reusing sibling placeholder parameters

src/​InterfaceStubGenerator.Shared/​Parser.Request.Parameters.cs:252

For /accounts/{Id}/positions/{ID} with (int id, [Query, AliasAs("ID")] int secondId), id scores 4 for both placeholders because it has no exact-case placeholder. It therefore beats secondId's exact-match score of 2 for {ID}. Arguments (10, 20) produce /accounts/10/positions/10?ID=20 instead of /accounts/10/positions/20.

The same ranking exists in src/Refit.Reflection/RestMethodInfoInternal.ParameterBinding.cs:264-266. Resolve assignments across the sibling group so the fallback for {Id} does not also take the sibling's exact {ID} binding. Update both builders and add this mixed-attribute case to the live parity tests; the existing mixed-attribute tests use exact {id}.

Review effort: Balanced

@glennawatson
glennawatson requested a balanced review from Copilot October 17, 2026 02:57

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 was unable to review this pull request because the user who requested the review has reached their quota limit.

@sonarqubecloud

Copy link
Copy Markdown

@glennawatson
glennawatson merged commit 8e03c5e into main Oct 17, 2026
30 checks passed
@glennawatson
glennawatson deleted the fix/open-issues-2356-2357-2359 branch October 17, 2026 03:14
@github-actions

Copy link
Copy Markdown

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions Bot locked and limited conversation to collaborators Nov 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

3 participants