-
Notifications
You must be signed in to change notification settings - Fork 5.3k
routing: enable routing on query arg match (#2120) #2258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -995,6 +995,99 @@ TEST(RouteMatcherTest, HeaderMatchedRouting) { | |
| } | ||
| } | ||
|
|
||
| TEST(RouteMatcherTest, QueryParamMatchedRouting) { | ||
| std::string json = R"EOF( | ||
| { | ||
| "virtual_hosts": [ | ||
| { | ||
| "name": "local_service", | ||
| "domains": ["*"], | ||
| "routes": [ | ||
| { | ||
| "prefix": "/", | ||
| "cluster": "local_service_with_multiple_query_parameters", | ||
| "query_parameters": [ | ||
| {"name": "id", "value": "\\d+[02468]", "regex": true}, | ||
| {"name": "debug"} | ||
| ] | ||
| }, | ||
| { | ||
| "prefix": "/", | ||
| "cluster": "local_service_with_query_parameter", | ||
| "query_parameters": [ | ||
| {"name": "param", "value": "test"} | ||
| ] | ||
| }, | ||
| { | ||
| "prefix": "/", | ||
| "cluster": "local_service_with_valueless_query_parameter", | ||
| "query_parameters": [ | ||
| {"name": "debug"} | ||
| ] | ||
| }, | ||
| { | ||
| "prefix": "/", | ||
| "cluster": "local_service_without_query_parameters" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| )EOF"; | ||
|
|
||
| NiceMock<Runtime::MockLoader> runtime; | ||
| NiceMock<Upstream::MockClusterManager> cm; | ||
| ConfigImpl config(parseRouteConfigurationFromJson(json), runtime, cm, true); | ||
|
|
||
| { | ||
| Http::TestHeaderMapImpl headers = genHeaders("example.com", "/", "GET"); | ||
| EXPECT_EQ("local_service_without_query_parameters", | ||
| config.route(headers, 0)->routeEntry()->clusterName()); | ||
| } | ||
|
|
||
| { | ||
| Http::TestHeaderMapImpl headers = genHeaders("example.com", "/?", "GET"); | ||
| EXPECT_EQ("local_service_without_query_parameters", | ||
| config.route(headers, 0)->routeEntry()->clusterName()); | ||
| } | ||
|
|
||
| { | ||
| Http::TestHeaderMapImpl headers = genHeaders("example.com", "/?param=testing", "GET"); | ||
| EXPECT_EQ("local_service_without_query_parameters", | ||
| config.route(headers, 0)->routeEntry()->clusterName()); | ||
| } | ||
|
|
||
| { | ||
| Http::TestHeaderMapImpl headers = genHeaders("example.com", "/?param=test", "GET"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a test for multiple query params?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I put a couple of multi-param tests a bit later in config_impl_test.cc: all parameters match and proper subset of parameters match. |
||
| EXPECT_EQ("local_service_with_query_parameter", | ||
| config.route(headers, 0)->routeEntry()->clusterName()); | ||
| } | ||
|
|
||
| { | ||
| Http::TestHeaderMapImpl headers = genHeaders("example.com", "/?debug", "GET"); | ||
| EXPECT_EQ("local_service_with_valueless_query_parameter", | ||
| config.route(headers, 0)->routeEntry()->clusterName()); | ||
| } | ||
|
|
||
| { | ||
| Http::TestHeaderMapImpl headers = genHeaders("example.com", "/?debug=2", "GET"); | ||
| EXPECT_EQ("local_service_with_valueless_query_parameter", | ||
| config.route(headers, 0)->routeEntry()->clusterName()); | ||
| } | ||
|
|
||
| { | ||
| Http::TestHeaderMapImpl headers = genHeaders("example.com", "/?param=test&debug&id=01", "GET"); | ||
| EXPECT_EQ("local_service_with_query_parameter", | ||
| config.route(headers, 0)->routeEntry()->clusterName()); | ||
| } | ||
|
|
||
| { | ||
| Http::TestHeaderMapImpl headers = genHeaders("example.com", "/?param=test&debug&id=02", "GET"); | ||
| EXPECT_EQ("local_service_with_multiple_query_parameters", | ||
| config.route(headers, 0)->routeEntry()->clusterName()); | ||
| } | ||
| } | ||
|
|
||
| class RouterMatcherHashPolicyTest : public testing::Test { | ||
| public: | ||
| RouterMatcherHashPolicyTest() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the idea here to avoid a bug where we could see for the
=beyond the next query param? If so, can you add a test for this?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, prior to this,
parseQueryStringhad a bug whereby it would interpretx&y=zas having two key-value variables:y, value=zx&y, value=zThis PR contains a test for that, on line 1079 of config_impl_test.cc.