Skip to content

fix(rewrite): look up rewrite metadata with an empty prefix when context-path is absent (#7796) - #7798

Merged
Aias00 merged 1 commit into
apache:masterfrom
konlue:fix/rewrite-metadata-prefix
Oct 19, 2026
Merged

Aias00 merged 1 commit into
apache:masterfrom
konlue:fix/rewrite-metadata-prefix

Conversation

@konlue

@konlue konlue commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Fixes #7796.

Summary

When the context-path plugin has not run, both the REWRITE_CONTEXT_PATH and fallback CONTEXT_PATH exchange attributes are null, so RewritePlugin builds its metadata lookup key as the literal string "null" + rewriteUri. A rewrite rule with rewriteMetaData=true therefore never finds metadata cached under the plain rewritten path.

Modifications

  • Default the absent context-path prefix to an empty string before concatenating with the rewritten URI, so the lookup key matches the path semantics used by the rewrite and context-path plugins.
  • Add a regression test: no context-path attributes, rewriteMetaData=true, metadata cached under the bare rewritten path — the resolved rpc type must come from the metadata.

Verifying this change

  • New RewritePluginTest#shouldLookUpMetaDataWithoutContextPath: fails on the current code (lookup misses, rpc type falls back to http) and passes with the fix.

  • Targeted tests pass:

    ./mvnw -B -ntp -pl shenyu-plugin/shenyu-plugin-rewrite test -Dtest=RewritePluginTest

    8/8 green.

  • Checkstyle passes:

    ./mvnw -B -ntp -pl shenyu-plugin/shenyu-plugin-rewrite checkstyle:check

    clean.

Notes

When a context path IS present the concatenated key is unchanged, so existing dubbo/other-rpc metadata lookups behave identically. No cache structure changes — only the key construction is made null-safe.

@Aias00 Aias00 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.

Approved.

Good fix. When neither the rewrite nor the global context-path attribute is set, the previous code concatenated a null attribute and produced the literal "null" lookup key, so metadata was never found. Wrapping with StringUtils.defaultString converts the absent path to an empty prefix, and the new shouldLookUpMetaDataWithoutContextPath test asserts the bare rewritten path resolves the metadata.

CI is green on this branch.

@Aias00
Aias00 merged commit 8bfdc9d into apache:master Oct 19, 2026
28 checks passed
@Aias00 Aias00 added this to the 2.7.2 milestone Nov 13, 2026
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.

[BUG] Rewrite metadata lookup uses a null path prefix when context-path is absent

2 participants