Fix CancellationToken body parameter bug for POST/PUT/PATCH methods#97
Merged
Conversation
Co-authored-by: twogood <189982+twogood@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Bug: for POST/PUT etc that take a body, if a CancellationToken is the last parameter it will be sent instead of the body
Fix CancellationToken body parameter bug for POST/PUT/PATCH methods
Aug 8, 2025
Owner
|
@copilot do not add dependency on any json package. Use a simple plain text body instead. Even if that is not the most common use case it is good enough for unit tests. |
…ext bodies Co-authored-by: twogood <189982+twogood@users.noreply.github.com>
Contributor
Author
Done! Removed the JSON package dependency and updated the tests to use plain text bodies instead. The tests are now much simpler and still effectively verify that CancellationToken parameters are not being used as request bodies. All tests continue to pass. (87f48ba) |
twogood
approved these changes
Aug 8, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes a bug where
CancellationTokenparameters were incorrectly being used as the request body for POST, PUT, and PATCH HTTP methods.Problem
When a REST client method had a
CancellationTokenas the last parameter, theRequestHandlerwould attempt to serialize it as the request body instead of using the actual body parameter. This caused serialization errors like:Root Cause
The
RequestHandlerconstructor always set_bodyArgumentIndexto_parameters.Length - 1(the last parameter), without considering that the last parameter might be aCancellationTokenthat should be handled separately.Solution
Added logic in the
RequestHandlerconstructor to detect when:CancellationTokenIn these cases, the body argument index is adjusted to use the second-to-last parameter (
_parameters.Length - 2) instead.Example
Before this fix, the following would fail:
Now it correctly serializes
dataas the request body and usescancellationTokenfor cancellation.Testing
Added comprehensive tests covering:
CancellationTokenas last parameterCancellationToken)CancellationTokenstill workAll existing tests continue to pass, ensuring no breaking changes.
Fixes #96.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.