Skip to content

Default Content-Type to application/json for generic error and custom rate-limit responses - #1986

Merged
waldekmastykarz merged 1 commit into
dotnet:mainfrom
waldekmastykarz:fix-1971-missing-content-type
Oct 26, 2026
Merged

waldekmastykarz merged 1 commit into
dotnet:mainfrom
waldekmastykarz:fix-1971-missing-content-type

Conversation

@waldekmastykarz

Copy link
Copy Markdown
Collaborator

Closes #1971

GenericRandomErrorPlugin responses and RateLimitingPlugin custom responses now get Content-Type: application/json when they have a body and no Content-Type header is configured. This mirrors how MockResponsePlugin defaults the content type. An explicitly configured Content-Type is preserved.

Tests

Added integration tests in BehaviorPluginsIntegrationTests:

  • generic error with a JSON body and no Content-Type → application/json
  • generic error with an explicit Content-Type → kept as-is, not duplicated
  • rate-limit custom response with a body → application/json
… rate-limit responses

GenericRandomErrorPlugin and RateLimitingPlugin (custom response) now add
Content-Type: application/json when the response has a body and no
Content-Type header is configured, matching MockResponsePlugin.

Closes dotnet#1971

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b01cdbfd-df85-41d9-925d-3fe22389de95
@waldekmastykarz
waldekmastykarz requested a review from a team as a code owner October 21, 2026 13:55
Copilot AI balanced review requested due to automatic review settings October 21, 2026 13:55

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.

🟢 Approval recommended

The narrow changes preserve configured headers and have focused integration coverage, with no blocking issues identified; tests were not executed.

No open issues 🎉

What changed in this PR

Aligns generated error and custom rate-limit responses with mock-response defaults, addressing #1971.

Changes:

  • Defaults Content-Type to application/json for non-null bodies.
  • Preserves explicitly configured content types.
  • Adds integration coverage for defaults and header preservation.
File Description
DevProxy.Plugins/​Behavior/​RateLimitingPlugin.cs Defaults content type for custom responses.
DevProxy.Plugins/​Behavior/​GenericRandomErrorPlugin.cs Defaults content type for error responses.
DevProxy.Integration.Tests/​BehaviorPluginsIntegrationTests.cs Tests defaults and explicit-header preservation.

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.

🟢 Approval recommended

The focused changes preserve configured headers and have relevant integration coverage; tests were not executed.

No open issues 🎉

Review effort: Balanced

@waldekmastykarz
waldekmastykarz merged commit 05d7b6a into dotnet:main Oct 26, 2026
4 checks passed
@waldekmastykarz
waldekmastykarz deleted the fix-1971-missing-content-type branch October 26, 2026 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants