Skip to content

Support environment variables in RewritePlugin replacement values - #1915

Merged
garrytrinder merged 1 commit into
dotnet:mainfrom
waldekmastykarz:waldekmastykarz-url-rewrite-env-vars
Oct 7, 2026
Merged

garrytrinder merged 1 commit into
dotnet:mainfrom
waldekmastykarz:waldekmastykarz-url-rewrite-env-vars

Conversation

@waldekmastykarz

Copy link
Copy Markdown
Collaborator

Adds support for referencing environment variables in RewritePlugin replacement values using ${env:VAR_NAME}.

Changes

  • out.url and out.headers[].value can contain ${env:VAR_NAME} tokens.
  • Values are inserted as-is, so in out.url they can reference capture groups from the in.url pattern.
  • Variables are resolved only for requests matching in.url. in.url itself isn't expanded.
  • If a referenced variable isn't set, the plugin logs an error and skips the rule (URL and headers).
  • Updated v4.0.0 rewrites file schema descriptions and skill references.
  • Added integration tests for expansion and missing-variable handling.

Example

{
  "rewrites": [
    {
      "in": { "url": "https://api.contoso.com/(.*)" },
      "out": {
        "url": "${env:API_BASE_URL}/$1",
        "headers": [ { "name": "Authorization", "value": "Bearer ${env:API_TOKEN}" } ]
      }
    }
  ]
}

Allow out.url and out.headers[].value to reference environment variables
using ${env:VAR_NAME}. Values are inserted as-is, so in out.url they can
reference capture groups from the in.url pattern. If a referenced
variable isn't set, the plugin logs an error and skips the rule.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a8d2f415-72ca-407f-ac8c-d88703338613
@waldekmastykarz
waldekmastykarz requested a review from a team as a code owner October 7, 2026 08:59
Copilot AI balanced review requested due to automatic review settings October 7, 2026 08:59

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

The implementation matches the documented behavior and includes appropriate integration coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Adds environment-variable expansion to RewritePlugin output values while safely skipping rules with missing variables.

Changes:

  • Expands ${env:VAR_NAME} in rewritten URLs and headers.
  • Adds integration coverage for expansion and missing variables.
  • Updates schema and skill documentation.
File Description
RewritePlugin.cs Implements environment-variable expansion.
ManipulationAndMockingIntegrationTests.cs Tests expansion and skipped rules.
rewriteplugin.rewritesfile.schema.json Documents supported tokens.
plugin-catalog.md Updates plugin reference.
configuration.md Updates configuration guidance.

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

@garrytrinder
garrytrinder merged commit cb1a94d into dotnet:main Oct 7, 2026
6 checks passed
@waldekmastykarz
waldekmastykarz deleted the waldekmastykarz-url-rewrite-env-vars branch October 7, 2026 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants