Skip to content

Add request header rewriting to RewritePlugin - #1904

Merged
garrytrinder merged 2 commits into
dotnet:mainfrom
waldekmastykarz:waldekmastykarz-rewrite-request-headers
Oct 2, 2026
Merged

garrytrinder merged 2 commits into
dotnet:mainfrom
waldekmastykarz:waldekmastykarz-rewrite-request-headers

Conversation

@waldekmastykarz

Copy link
Copy Markdown
Collaborator

Adds the ability to set request header values with RewritePlugin.

Changes

  • Rewrite rules support out.headers ([{ "name", "value" }]).
  • out.url is now optional, so a rule can match on in.url and only change headers.
  • Header names are matched case-insensitively. An existing header's value is replaced; a missing header is added.
  • Header rewrites apply only when in.url matches the request URL (evaluated before that rule's URL rewrite).
  • Updated the v4.0.0 rewrites file schema and the skill reference docs.
  • Added integration tests.

Example

{
  "rewrites": [
    {
      "in": { "url": "^https://api\\.contoso\\.com/" },
      "out": { "headers": [ { "name": "Authorization", "value": "Bearer test-token" } ] }
    }
  ]
}
Rewrite rules can now set request header values via out.headers.
out.url is optional, so a rule can match on in.url and only change
headers. Existing headers are replaced (case-insensitive); missing
headers are added.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 2, 2026 12:39
@waldekmastykarz
waldekmastykarz requested a review from a team as a code owner October 2, 2026 12:39

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

Null header entries can abort remaining rewrite rules, and combined URL-and-header behavior needs regression coverage.

Review effort: Balanced
Findings: 1 High severity · 1 Medium severity

Open (2)
What changed in this PR

Adds request-header rewriting to Dev Proxy’s RewritePlugin alongside existing URL rewriting.

Changes:

  • Supports header-only rules and case-insensitive header replacement.
  • Updates the v4.0.0 schema and configuration references.
  • Adds integration tests for matching and nonmatching requests.
File Description
skills/​dev-proxy/​references/​plugin-catalog.md Documents header rewriting.
skills/​dev-proxy/​references/​configuration.md Describes optional rewrite outputs.
schemas/​v4.0.0/​rewriteplugin.rewritesfile.schema.json Allows headers and optional URL output.
DevProxy.Plugins/​Manipulation/​RewritePlugin.cs Applies matching header rewrites.
DevProxy.Integration.Tests/​ManipulationAndMockingIntegrationTests.cs Tests header addition, replacement, and nonmatches.

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

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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

🟢 Approval recommended

Only minor, nonblocking documentation and performance improvements remain; both previously reported issues are resolved.

Review effort: Balanced
Findings: None

Resolved since last review (2)
@garrytrinder
garrytrinder merged commit 4a509da into dotnet:main Oct 2, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants