feat: expose rule regex captures to rewriters - #1104
Open
houyuwushang wants to merge 1 commit into
Open
Conversation
Signed-off-by: houyuwushang <liuluoqianqiu@outlook.com>
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.
Description
Adds regex capture expansion to Rule Router request rewriters. An
rmatchrule now exposes${0}, numbered submatches such as${1}, and named submatches such as${tenant}to the matched case rewriter and that rule's egress rewriter. Captures are request-scoped and cleared before the next route.The change also makes explicit scheme, host, hostname, and port rewrites apply to the final upstream URL. Because a captured hostname can select a different origin, the final rewritten authority participates in cache identity to prevent responses from different origins sharing an entry.
Existing rules without token-bearing rewriters do not calculate capture maps. Undefined tokens remain unchanged, optional unmatched captures expand to an empty string, and expansion is non-recursive. The documentation includes the decoded-path behavior from the original example and warns that client-derived authorities require restrictive regular expressions because configured credentials follow the selected origin.
Fixes #598.
Validation
go test -count=20 ./pkg/backends/rule ./pkg/proxy/request/rewritergo test -race -count=5 ./pkg/backends/rule ./pkg/proxy/request/rewritergo test -count=1 ./pkg/backends/... ./pkg/proxy/...go vet ./pkg/backends/... ./pkg/proxy/...go tool golangci-lint run --timeout 5m -c .golangci.yml ./pkg/backends/rule/... ./pkg/proxy/request/rewriter/... ./pkg/proxy/urls/... ./pkg/proxy/engines/...Type of Change
AI Disclosure