Skip to content

Conversation

wbpcode
Copy link
Member

@wbpcode wbpcode commented Oct 11, 2025

Commit Message: route: add substitution formatter for path/host rewrite
Additional Description:

This PR add substitution formatting support to host/path rewrite. Now we can rewrite the host/path in same way like rewriting other headers in header_mutation or request_headers_to_add.

The substitution is used for logging, header mutation, rate limiting, now, it also could be used for host/path header rewriting.

Risk Level: low.
Testing: unit.
Docs Changes: n/a.
Release Notes: added.
Platform Specific Features: n/a.

Copy link

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to (api/envoy/|docs/root/api-docs/).
envoyproxy/api-shepherds assignee is @markdroth
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).

🐱

Caused by: #41468 was opened by wbpcode.

see: more, trace.

Http::TestRequestHeaderMapImpl headers =
genHeaders("api.lyft.com", "/rewrite-host-with-header-value", "GET");
const RouteEntry* route_entry = config.route(headers, 0)->routeEntry();
EXPECT_FALSE(route_entry->currentUrlPathAfterRewrite(headers).has_value());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We needn't test test this everywhere because the finalizeRequestHeaders will call this method to generate new path anyway.

//
// If the final output of the path rewrite is empty, then the update will be ignored and the
// original path will be preserved.
string path_rewrite = 45;
Copy link
Member Author

@wbpcode wbpcode Oct 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a general solution for path/host rewriting because it could cover almost all exist features but provide more features, flexibility and extensibility.

Signed-off-by: WangBaiping <[email protected]>
@wbpcode
Copy link
Member Author

wbpcode commented Oct 12, 2025

/retest

@agrawroh
Copy link
Member

agrawroh commented Oct 13, 2025

@wbpcode Thank you so much for adding this feature. We have a similar use-case where we want to rewrite the paths based on another incoming header from the request. For example, the requests comes with a path /foo/bar and it needs to be re-written as /foo/<uuid>/bar where UUID is determined by AuthService (ExtAuthZ) after parsing the authorization token. Auth adds the new UUID header back to the request stream after processing.

With this feature, I could simply do something like /foo/%REQ(x-uuid-hdr)%/bar which wasn't an option before. We were writing custom LUA code to replace :path after mutations as we wanted.

@botengyao
Copy link
Member

/retest

@wbpcode wbpcode assigned abeyad and unassigned markdroth Oct 18, 2025
@wbpcode
Copy link
Member Author

wbpcode commented Oct 18, 2025

Re-assign this to @abeyad to give a API review because seems Mark is focus on gRPC recently.

@wbpcode wbpcode assigned mattklein123 and unassigned abeyad Oct 18, 2025
@wbpcode
Copy link
Member Author

wbpcode commented Oct 18, 2025

Sorry for the noise. I think of this require a senior maintainer to review the code anyway. So, let Matt to cover both the API and code directly. Matt, thanks 🙏

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@wbpcode wbpcode merged commit 5c15c21 into envoyproxy:main Oct 19, 2025
26 checks passed
@wbpcode wbpcode deleted the dev-to-support-substitution-formatter-for-path-host-rewrite branch October 19, 2025 01:35
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.

6 participants