Skip to content
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
19 changes: 3 additions & 16 deletions internal/envoy/v3/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"bytes"
"fmt"
"net/http"
"regexp"
"sort"
"strings"
"text/template"
Expand Down Expand Up @@ -825,23 +824,11 @@ func queryParamMatcher(queryParams []dag.QueryParamMatchCondition) []*envoy_rout
// containsMatch returns a HeaderMatchSpecifier which will match the
// supplied substring
func containsMatch(s string, ignoreCase bool) *envoy_route_v3.HeaderMatcher_StringMatch {
// convert the substring s into a regular expression that matches s.
// note that Envoy expects the expression to match the entire string, not just the substring
// formed from s. see [projectcontour/contour/#1751 & envoyproxy/envoy#8283]
var regex string
if ignoreCase {
regex = fmt.Sprintf("(?i).*%s.*", regexp.QuoteMeta(s))
} else {
regex = fmt.Sprintf(".*%s.*", regexp.QuoteMeta(s))
}

// This could also be implemented with contains envoy Matcher but the problem
// would be that it will be a breaking change for contour due to the way the
// envoy handles empty strings.
return &envoy_route_v3.HeaderMatcher_StringMatch{
StringMatch: &matcher.StringMatcher{
MatchPattern: &matcher.StringMatcher_SafeRegex{
SafeRegex: SafeRegexMatch(regex),
IgnoreCase: ignoreCase,
MatchPattern: &matcher.StringMatcher_Contains{
Contains: s,
},
},
}
Expand Down
21 changes: 11 additions & 10 deletions internal/envoy/v3/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1872,8 +1872,8 @@ func TestRouteMatch(t *testing.T) {
InvertMatch: false,
HeaderMatchSpecifier: &envoy_route_v3.HeaderMatcher_StringMatch{
StringMatch: &matcher.StringMatcher{
MatchPattern: &matcher.StringMatcher_SafeRegex{
SafeRegex: SafeRegexMatch(".*11-22-33-44.*"),
MatchPattern: &matcher.StringMatcher_Contains{
Contains: "11-22-33-44",
},
},
},
Expand All @@ -1895,8 +1895,8 @@ func TestRouteMatch(t *testing.T) {
InvertMatch: false,
HeaderMatchSpecifier: &envoy_route_v3.HeaderMatcher_StringMatch{
StringMatch: &matcher.StringMatcher{
MatchPattern: &matcher.StringMatcher_SafeRegex{
SafeRegex: SafeRegexMatch(".*11\\.22\\.33\\.44.*"),
MatchPattern: &matcher.StringMatcher_Contains{
Contains: "11.22.33.44",
},
},
},
Expand All @@ -1918,8 +1918,8 @@ func TestRouteMatch(t *testing.T) {
InvertMatch: false,
HeaderMatchSpecifier: &envoy_route_v3.HeaderMatcher_StringMatch{
StringMatch: &matcher.StringMatcher{
MatchPattern: &matcher.StringMatcher_SafeRegex{
SafeRegex: SafeRegexMatch(".*11\\.\\[22\\]\\.\\*33\\.44.*"),
MatchPattern: &matcher.StringMatcher_Contains{
Contains: "11.[22].*33.44",
},
},
},
Expand Down Expand Up @@ -2141,8 +2141,8 @@ func TestRouteMatch(t *testing.T) {
Name: "x-header-foo",
HeaderMatchSpecifier: &envoy_route_v3.HeaderMatcher_StringMatch{
StringMatch: &matcher.StringMatcher{
MatchPattern: &matcher.StringMatcher_SafeRegex{
SafeRegex: SafeRegexMatch(".*bar.*"),
MatchPattern: &matcher.StringMatcher_Contains{
Contains: "bar",
},
},
},
Expand All @@ -2163,8 +2163,9 @@ func TestRouteMatch(t *testing.T) {
Name: "x-header-foo",
HeaderMatchSpecifier: &envoy_route_v3.HeaderMatcher_StringMatch{
StringMatch: &matcher.StringMatcher{
MatchPattern: &matcher.StringMatcher_SafeRegex{
SafeRegex: SafeRegexMatch("(?i).*bar.*"),
IgnoreCase: true,
MatchPattern: &matcher.StringMatcher_Contains{
Contains: "bar",
},
},
},
Expand Down