Repository navigation
Send string response bodies as-is instead of JSON-serializing them - #1994
Open
waldekmastykarz wants to merge 1 commit into
Open
waldekmastykarz wants to merge 1 commit into
waldekmastykarz wants to merge 1 commit into
Conversation
String `body` values in GenericRandomErrorPlugin errors, RateLimitingPlugin custom responses, and MockResponsePlugin mocks were JSON-serialized, so `"body": "hello"` was sent as `"hello"` including the quotes. String bodies are now sent verbatim; non-string bodies are still serialized as JSON and `@file` bodies still load the response from disk. Closes dotnet#1970 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 5a24c559-2e14-4f92-b083-5e42f0e6a6f8
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The focused serialization changes have regression coverage for all three affected plugins, with no unresolved findings.
No open issues 🎉
What changed in this PR
Fixes #1970 by sending configured string response bodies without JSON-added quotes across three plugins.
Changes:
- Adds shared body serialization that preserves strings and JSON-serializes other values.
- Updates affected plugins while preserving existing
@filehandling. - Adds regression tests and exact-body assertions.
| File | Description |
|---|---|
| DevProxy.Plugins/Mocking/MockResponsePlugin.cs | Preserves raw strings and file-body handling. |
| DevProxy.Plugins/Behavior/RateLimitingPlugin.cs | Preserves custom response strings. |
| DevProxy.Plugins/Behavior/GenericRandomErrorPlugin.cs | Preserves error strings and file-body handling. |
| DevProxy.Integration.Tests/ManipulationAndMockingIntegrationTests.cs | Asserts exact mock response content. |
| DevProxy.Integration.Tests/BehaviorPluginsIntegrationTests.cs | Tests error and rate-limit string responses. |
| DevProxy.Abstractions/Utils/ProxyUtils.cs | Adds shared SerializeBody helper. |
| DevProxy.Abstractions.Tests/Utils/ProxyUtilsTests.cs | Tests null, string, and object serialization. |
Review effort: Balanced
This branch has not been deployed
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.
Closes #1970
Problem
A string
bodyin GenericRandomErrorPlugin errors, RateLimitingPlugin custom responses, and MockResponsePlugin mocks was JSON-serialized, so"body": "hello"was sent as"hello"(with quotes).Change
ProxyUtils.SerializeBody: strings (including JSON string elements) are returned as-is; other values are still serialized as JSON;nullreturns an empty string.@filebodies still load the response from disk.Tests
ProxyUtils.SerializeBody.DevProxy.Abstractions.Tests,DevProxy.Integration.Tests(95/95), andDevProxy.Testsall pass.