Skip to content
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

router: extend HTTP CONNECT route matching criteria #13056

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions source/common/router/config_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1056,9 +1056,10 @@ void ConnectRouteEntryImpl::rewritePathHeader(Http::RequestHeaderMap& headers,
}

RouteConstSharedPtr ConnectRouteEntryImpl::matches(const Http::RequestHeaderMap& headers,
const StreamInfo::StreamInfo&,
const StreamInfo::StreamInfo& stream_info,
uint64_t random_value) const {
if (Http::HeaderUtility::isConnect(headers)) {
if (Http::HeaderUtility::isConnect(headers) &&
RouteEntryImplBase::matchRoute(headers, stream_info, random_value)) {
return clusterEntry(headers, random_value);
}
return nullptr;
Expand Down
29 changes: 25 additions & 4 deletions test/common/router/config_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,8 @@ TEST_F(RouteMatcherTest, TestConnectRoutes) {
route:
cluster: connect_break
- match:
connect_matcher:
{}
connect_matcher:
{}
route:
cluster: connect_match
prefix_rewrite: "/rewrote"
Expand All @@ -507,9 +507,21 @@ TEST_F(RouteMatcherTest, TestConnectRoutes) {
- bat4.com
routes:
- match:
connect_matcher:
{}
connect_matcher:
{}
redirect: { path_redirect: /new_path }
- name: connect3
domains:
- bat5.com
routes:
- match:
connect_matcher:
{}
headers:
- name: x-safe
exact_match: "safe"
route:
cluster: connect_header_match
- name: default
domains:
- "*"
Expand Down Expand Up @@ -557,6 +569,15 @@ TEST_F(RouteMatcherTest, TestConnectRoutes) {
redirect->rewritePathHeader(headers, true);
EXPECT_EQ("http://bat4.com/new_path", redirect->newPath(headers));
}

// Header matching (for HTTP/1.1)
EXPECT_EQ(
"connect_header_match",
config.route(genPathlessHeaders("bat5.com", "CONNECT"), 0)->routeEntry()->clusterName());

// Header matching (for HTTP/2)
EXPECT_EQ("connect_header_match",
config.route(genHeaders("bat5.com", " ", "CONNECT"), 0)->routeEntry()->clusterName());
}

TEST_F(RouteMatcherTest, TestRoutes) {
Expand Down