Commit 86b2d1aa authored by Geoff Simmons's avatar Geoff Simmons

DRY -- use only one CompareType in VCL spec types.

parent bfff5b5d
......@@ -454,6 +454,37 @@ func (worker *NamespaceWorker) configSharding(spec *vcl.Spec,
return nil
}
func configComparison(cmp vcr_v1alpha1.CompareType) (vcl.CompareType, bool) {
switch cmp {
case vcr_v1alpha1.Equal:
return vcl.Equal, false
case vcr_v1alpha1.NotEqual:
return vcl.Equal, true
case vcr_v1alpha1.Match:
return vcl.Match, false
case vcr_v1alpha1.NotMatch:
return vcl.Match, true
case vcr_v1alpha1.Prefix:
return vcl.Prefix, false
case vcr_v1alpha1.NotPrefix:
return vcl.Prefix, true
case vcr_v1alpha1.Exists:
return vcl.Exists, false
case vcr_v1alpha1.NotExists:
return vcl.Exists, true
case vcr_v1alpha1.Greater:
return vcl.Greater, false
case vcr_v1alpha1.GreaterEqual:
return vcl.GreaterEqual, false
case vcr_v1alpha1.Less:
return vcl.Less, false
case vcr_v1alpha1.LessEqual:
return vcl.LessEqual, false
default:
return vcl.Equal, false
}
}
func configConditions(vclConds []vcl.MatchTerm,
vcfgConds []vcr_v1alpha1.Condition) {
......@@ -465,18 +496,8 @@ func configConditions(vclConds []vcl.MatchTerm,
Comparand: cond.Comparand,
Value: cond.Value,
}
switch cond.Compare {
case vcr_v1alpha1.Equal:
vclMatch.Compare = vcl.Equal
case vcr_v1alpha1.NotEqual:
vclMatch.Compare = vcl.NotEqual
case vcr_v1alpha1.Match:
vclMatch.Compare = vcl.Match
case vcr_v1alpha1.NotMatch:
vclMatch.Compare = vcl.NotMatch
default:
vclMatch.Compare = vcl.Equal
}
vclMatch.Compare, vclMatch.Negate =
configComparison(cond.Compare)
vclConds[i] = vclMatch
}
}
......@@ -688,16 +709,10 @@ func (worker *NamespaceWorker) configRewrites(spec *vcl.Spec,
return fmt.Errorf("Illegal method %s", rw.Method)
}
switch rw.Compare {
case vcr_v1alpha1.Match:
vclRw.Compare = vcl.RewriteMatch
case vcr_v1alpha1.Equal:
vclRw.Compare = vcl.RewriteEqual
case vcr_v1alpha1.Prefix:
vclRw.Compare = vcl.Prefix
default:
vclRw.Compare = vcl.RewriteMatch
if rw.Compare == "" {
rw.Compare = vcr_v1alpha1.Match
}
vclRw.Compare, vclRw.Negate = configComparison(rw.Compare)
switch rw.VCLSub {
case vcr_v1alpha1.Recv:
......@@ -783,42 +798,8 @@ func (worker *NamespaceWorker) configReqDisps(spec *vcl.Spec,
count := uint(*cond.Count)
vclCond.Count = &count
}
switch cond.Compare {
case vcr_v1alpha1.Equal:
vclCond.Compare = vcl.ReqEqual
vclCond.Negate = false
case vcr_v1alpha1.NotEqual:
vclCond.Compare = vcl.ReqEqual
vclCond.Negate = true
case vcr_v1alpha1.Match:
vclCond.Compare = vcl.ReqMatch
vclCond.Negate = false
case vcr_v1alpha1.NotMatch:
vclCond.Compare = vcl.ReqMatch
vclCond.Negate = true
case vcr_v1alpha1.Prefix:
vclCond.Compare = vcl.ReqPrefix
vclCond.Negate = false
case vcr_v1alpha1.NotPrefix:
vclCond.Compare = vcl.ReqPrefix
vclCond.Negate = true
case vcr_v1alpha1.Exists:
vclCond.Compare = vcl.Exists
vclCond.Negate = false
case vcr_v1alpha1.NotExists:
vclCond.Compare = vcl.Exists
vclCond.Negate = true
case vcr_v1alpha1.Greater:
vclCond.Compare = vcl.Greater
case vcr_v1alpha1.GreaterEqual:
vclCond.Compare = vcl.GreaterEqual
case vcr_v1alpha1.Less:
vclCond.Compare = vcl.Less
case vcr_v1alpha1.LessEqual:
vclCond.Compare = vcl.LessEqual
default:
vclCond.Compare = vcl.ReqEqual
}
vclCond.Compare, vclCond.Negate =
configComparison(cond.Compare)
if cond.MatchFlags != nil {
vclCond.MatchFlags = configMatchFlags(
*cond.MatchFlags)
......
......@@ -315,7 +315,7 @@ var reqDispHarness = []struct {
Conditions: []vcl.Condition{
vcl.Condition{
Comparand: "req.method",
Compare: vcl.ReqEqual,
Compare: vcl.Equal,
Values: []string{"PRI"},
MatchFlags: vcl.MatchFlagsType{
CaseSensitive: true,
......@@ -339,7 +339,7 @@ var reqDispHarness = []struct {
},
vcl.Condition{
Comparand: "req.esi_level",
Compare: vcl.ReqEqual,
Compare: vcl.Equal,
Count: &uintZero,
MatchFlags: vcl.MatchFlagsType{
CaseSensitive: true,
......@@ -347,7 +347,7 @@ var reqDispHarness = []struct {
},
vcl.Condition{
Comparand: "req.proto",
Compare: vcl.ReqPrefix,
Compare: vcl.Prefix,
Values: []string{"HTTP/1.1"},
},
},
......@@ -360,7 +360,7 @@ var reqDispHarness = []struct {
Conditions: []vcl.Condition{
vcl.Condition{
Comparand: "req.method",
Compare: vcl.ReqEqual,
Compare: vcl.Equal,
Negate: true,
Values: []string{
"GET",
......@@ -385,7 +385,7 @@ var reqDispHarness = []struct {
Conditions: []vcl.Condition{
vcl.Condition{
Comparand: "req.method",
Compare: vcl.ReqEqual,
Compare: vcl.Equal,
Negate: true,
Values: []string{
"GET",
......@@ -471,7 +471,7 @@ var reqDispHarness = []struct {
Conditions: []vcl.Condition{
vcl.Condition{
Comparand: "req.method",
Compare: vcl.ReqEqual,
Compare: vcl.Equal,
Values: []string{"CONNECT"},
MatchFlags: vcl.MatchFlagsType{
CaseSensitive: true,
......@@ -486,7 +486,7 @@ var reqDispHarness = []struct {
Conditions: []vcl.Condition{
vcl.Condition{
Comparand: "req.method",
Compare: vcl.ReqEqual,
Compare: vcl.Equal,
Negate: true,
Values: []string{
"GET",
......@@ -551,7 +551,7 @@ var reqDispHarness = []struct {
Conditions: []vcl.Condition{
vcl.Condition{
Comparand: "req.url",
Compare: vcl.ReqMatch,
Compare: vcl.Match,
Values: []string{
`\.png$`,
`\.jpe?g$`,
......@@ -571,7 +571,7 @@ var reqDispHarness = []struct {
Conditions: []vcl.Condition{
vcl.Condition{
Comparand: "req.url",
Compare: vcl.ReqPrefix,
Compare: vcl.Prefix,
Values: []string{
"/interactive/",
"/basket/",
......@@ -608,7 +608,7 @@ var reqDispHarness = []struct {
Conditions: []vcl.Condition{
vcl.Condition{
Comparand: "req.method",
Compare: vcl.ReqEqual,
Compare: vcl.Equal,
Values: []string{"PURGE"},
MatchFlags: vcl.MatchFlagsType{
CaseSensitive: true,
......@@ -646,7 +646,7 @@ var reqDispHarness = []struct {
Conditions: []vcl.Condition{
vcl.Condition{
Comparand: "req.url",
Compare: vcl.ReqPrefix,
Compare: vcl.Prefix,
Negate: true,
Values: []string{
"/foo/",
......
......@@ -16,7 +16,7 @@ sub vcl_recv {
{{- range .ACLs}}
if (
{{- range $cond := .Conditions}}
{{$cond.Comparand}} {{cmpRelation .Compare}} "{{.Value}}" &&
{{$cond.Comparand}} {{cmpRelation .Compare .Negate}} "{{.Value}}" &&
{{- end}}
{{aclCmp .Comparand}} {{if .Whitelist}}!{{end}}~ {{aclName .Name}}
) {
......
......@@ -14,8 +14,8 @@ sub vcl_init {
sub vcl_recv {
{{- range .Auths}}
if (
{{- range $cond := .Conditions}}
{{$cond.Comparand}} {{cmpRelation .Compare}} "{{.Value}}" &&
{{- range .Conditions}}
{{.Comparand}} {{cmpRelation .Compare .Negate}} "{{.Value}}" &&
{{- end}}
{{- if eq .Status 401}}
!{{credsMatcher .Realm}}.match(req.http.Authorization)
......
......@@ -6,11 +6,11 @@ import selector;
{{range $cidx, $c := .Conditions -}}
{{if reqNeedsMatcher $c -}}
sub vcl_init {
new {{reqObj $didx $cidx}} = {{reqVMOD $c}}.set({{reqFlags $c}});
new {{reqObj $didx $cidx}} = {{vmod $c.Compare}}.set({{reqFlags $c}});
{{- range $val := $c.Values}}
{{reqObj $didx $cidx}}.add("{{$val}}");
{{- end}}
{{- if reqNeedsCompile $c}}
{{- if needsCompile $c.Compare}}
{{reqObj $didx $cidx}}.compile();
{{- end}}
}
......@@ -24,13 +24,13 @@ sub vcl_recv {
{{- range $cidx, $cond := .Conditions}}
{{- if ne $cidx 0}} &&
{{end}}
{{- if $cond.Negate}}! {{end}}
{{- if .Negate}}! {{end}}
{{- if reqNeedsMatcher $cond}}
{{- reqObj $didx $cidx}}.{{reqMatch $cond}}({{$cond.Comparand}})
{{- else if exists $cond.Compare}}
{{- $cond.Comparand}}
{{- reqObj $didx $cidx}}.{{match .Compare}}({{.Comparand}})
{{- else if exists .Compare}}
{{- .Comparand}}
{{- else}}
{{- $cond.Comparand}} {{reqCmpRelation $cond}} {{value $cond}}
{{- .Comparand}} {{cmpRelation .Compare .Negate}} {{value $cond}}
{{- end}}
{{- end -}}
) {
......
......@@ -37,7 +37,7 @@ var builtinRecvSpec = Spec{
{
Conditions: []Condition{{
Comparand: "req.method",
Compare: ReqEqual,
Compare: Equal,
Values: []string{"PRI"},
}},
Disposition: DispositionType{
......@@ -54,12 +54,12 @@ var builtinRecvSpec = Spec{
},
{
Comparand: "req.esi_level",
Compare: ReqEqual,
Compare: Equal,
Count: &zero,
},
{
Comparand: "req.proto",
Compare: ReqPrefix,
Compare: Prefix,
Values: []string{"HTTP/1.1"},
MatchFlags: MatchFlagsType{
CaseSensitive: false,
......@@ -74,7 +74,7 @@ var builtinRecvSpec = Spec{
{
Conditions: []Condition{{
Comparand: "req.method",
Compare: ReqEqual,
Compare: Equal,
Negate: true,
Values: []string{
"GET",
......@@ -96,7 +96,7 @@ var builtinRecvSpec = Spec{
{
Conditions: []Condition{{
Comparand: "req.method",
Compare: ReqEqual,
Compare: Equal,
Negate: true,
Values: []string{
"GET",
......@@ -140,7 +140,7 @@ var pipeOnConnectSpec = Spec{
Dispositions: []DispositionSpec{{
Conditions: []Condition{{
Comparand: "req.method",
Compare: ReqEqual,
Compare: Equal,
Values: []string{"CONNECT"},
}},
Disposition: DispositionType{
......@@ -158,7 +158,7 @@ var methodNotAllowedSpec = Spec{
Dispositions: []DispositionSpec{{
Conditions: []Condition{{
Comparand: "req.method",
Compare: ReqEqual,
Compare: Equal,
Negate: true,
Values: []string{
"GET",
......@@ -189,7 +189,7 @@ var urlWhitelistSpec = Spec{
Dispositions: []DispositionSpec{{
Conditions: []Condition{{
Comparand: "req.url",
Compare: ReqPrefix,
Compare: Prefix,
Negate: true,
Values: []string{
"/foo",
......@@ -217,7 +217,7 @@ var purgeMethodSpec = Spec{
Dispositions: []DispositionSpec{{
Conditions: []Condition{{
Comparand: "req.method",
Compare: ReqEqual,
Compare: Equal,
Values: []string{"PURGE"},
}},
Disposition: DispositionType{
......@@ -235,7 +235,7 @@ var cacheableSpec = Spec{
Dispositions: []DispositionSpec{{
Conditions: []Condition{{
Comparand: "req.url",
Compare: ReqMatch,
Compare: Match,
Values: []string{
`\.png$`,
`\.jpe?g$`,
......@@ -261,7 +261,7 @@ var nonCacheableSpec = Spec{
Dispositions: []DispositionSpec{{
Conditions: []Condition{{
Comparand: "req.url",
Compare: ReqPrefix,
Compare: Prefix,
Values: []string{
"/interactive/",
"/basket/",
......
......@@ -5,7 +5,7 @@ import selector;
{{range $i, $r := .Rewrites -}}
{{if needsMatcher $r -}}
sub vcl_init {
new {{rewrName $i}} = {{rewrVMOD $r}}.set({{rewrFlags $r}});
new {{rewrName $i}} = {{vmod $r.Compare}}.set({{rewrFlags $r}});
{{- range $rule := $r.Rules}}
{{rewrName $i}}.add("{{$rule.Value}}", string="{{$rule.Rewrite}}"
{{- if needsSave $r}}, save=true{{end -}}
......@@ -13,7 +13,7 @@ sub vcl_init {
{{- if needsNeverCapture $r}}, never_capture=true{{end -}}
);
{{- end}}
{{- if needsCompile $r}}
{{- if needsCompile $r.Compare}}
{{rewrName $i}}.compile();
{{- end}}
}
......@@ -21,7 +21,7 @@ sub vcl_init {
sub vcl_{{rewrSub $r}} {
{{- if needsMatcher $r}}
if ({{rewrName $i}}.{{rewrMatch $r}}({{$r.Source}})) {
if ({{rewrName $i}}.{{match $r.Compare}}({{$r.Source}})) {
{{- if needsUniqueCheck $r}}
if ({{rewrName $i}}.nmatches() != 1) {
std.log({{$r.Source}} + " had " +
......
......@@ -92,7 +92,7 @@ var replaceFromRewriteTest = Spec{
Rewrites: []Rewrite{{
Target: "req.http.Host",
Source: "req.http.Host",
Compare: RewriteEqual,
Compare: Equal,
Rules: []RewriteRule{
{
Value: "cafe.example.com",
......@@ -119,7 +119,7 @@ var rewriteSubTest = Spec{
Rewrites: []Rewrite{{
Target: "req.url",
Source: "req.url",
Compare: RewriteMatch,
Compare: Match,
Rules: []RewriteRule{
{
Value: `/foo(/|$)`,
......@@ -202,7 +202,7 @@ var conditionalDeleteTest = Spec{
Target: "resp.http.Via",
Source: "req.http.Delete-Via",
Method: Delete,
Compare: RewriteEqual,
Compare: Equal,
Rules: []RewriteRule{
{Value: "true"},
{Value: "yes"},
......@@ -222,9 +222,10 @@ func TestConditionalDelete(t *testing.T) {
var rewriteExtractTest = Spec{
Rewrites: []Rewrite{{
Target: "req.url",
Source: "req.url",
Method: RewriteMethod,
Target: "req.url",
Source: "req.url",
Method: RewriteMethod,
Compare: Match,
Rules: []RewriteRule{{
Value: `/([^/]+)/([^/]+)(.*)`,
Rewrite: `/\2/\1\3`,
......@@ -272,7 +273,7 @@ var rewriteFixedEqualTest = Spec{
Rewrites: []Rewrite{{
Target: "bereq.url",
Source: "bereq.url",
Compare: RewriteEqual,
Compare: Equal,
Method: Sub,
Rules: []RewriteRule{
{
......@@ -326,7 +327,7 @@ var rewritePrefixRegex = Spec{
Rewrites: []Rewrite{{
Target: "bereq.url",
Source: "bereq.url",
Compare: RewriteMatch,
Compare: Match,
Method: Sub,
Rules: []RewriteRule{
{
......@@ -355,7 +356,7 @@ var rewritePrependIfExists = Spec{
Rewrites: []Rewrite{{
Target: "resp.http.X-Bazz",
Source: "req.http.X-Bazz",
Compare: RewriteMatch,
Compare: Match,
Method: Prepend,
Rules: []RewriteRule{
{
......@@ -378,7 +379,7 @@ var rewriteExtractCookie = Spec{
Rewrites: []Rewrite{{
Target: "req.http.Session-Token",
Source: "req.http.Cookie",
Compare: RewriteMatch,
Compare: Match,
Method: RewriteMethod,
Rules: []RewriteRule{{
Value: `\bmysession\s*=\s*([^,;[:space:]]+)`,
......@@ -461,9 +462,10 @@ func TestRewriteAppendFromSrcTest(t *testing.T) {
var rewriteAppendRule = Spec{
Rewrites: []Rewrite{{
Target: "resp.http.Append-Rule-Target",
Source: "req.http.Append-Rule-Src",
Method: Append,
Target: "resp.http.Append-Rule-Target",
Source: "req.http.Append-Rule-Src",
Method: Append,
Compare: Match,
Rules: []RewriteRule{{
Value: `.`,
Rewrite: `AppendString`,
......@@ -649,10 +651,11 @@ var rewriteSelectOperations = Spec{
},
},
{
Target: "resp.http.Hdr",
Source: "req.url",
Select: First,
Method: Sub,
Target: "resp.http.Hdr",
Source: "req.url",
Compare: Match,
Select: First,
Method: Sub,
Rules: []RewriteRule{{
Value: `/foo`,
Rewrite: `foo`,
......@@ -662,10 +665,11 @@ var rewriteSelectOperations = Spec{
},
},
{
Target: "resp.http.Hdr",
Source: "req.url",
Select: Last,
Method: Suball,
Target: "resp.http.Hdr",
Source: "req.url",
Compare: Match,
Select: Last,
Method: Suball,
Rules: []RewriteRule{{
Value: `/foo`,
Rewrite: `foo`,
......@@ -675,10 +679,11 @@ var rewriteSelectOperations = Spec{
},
},
{
Target: "resp.http.Hdr",
Source: "req.url",
Select: First,
Method: RewriteMethod,
Target: "resp.http.Hdr",
Source: "req.url",
Compare: Match,
Select: First,
Method: RewriteMethod,
Rules: []RewriteRule{{
Value: `/foo`,
Rewrite: `foo`,
......
......@@ -315,19 +315,34 @@ func (a byACLAddr) Len() int { return len(a) }
func (a byACLAddr) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a byACLAddr) Less(i, j int) bool { return a[i].Addr < a[j].Addr }
// CompareType classifies comparisons for MatchTerm.
// CompareType classifies comparison operations performed for
// conditional configurations. The comparison may be negated if the
// boolean Negate field is true.
type CompareType uint8
const (
// Equal means compare strings for equality (==).
// Equal specifies equality -- string equality, numeric
// equality, or membership in a set of fixed strings.
Equal CompareType = iota
// NotEqual means compare with !=.
NotEqual
// Match means compare for regex match (~) -- the MatchTerm
// Value is a regular expression.
// Match specifies a regular expression match.
Match
// NotMatch means compare with !~.
NotMatch
// Prefix specifies that a string has a prefix in a set of
// fixed strings.
Prefix
// Exists specifies that a request header exists.
Exists
// Greater specifies the > relation between a VCL variable
// with a numeric value and a constant.
Greater
// GreaterEqual specifies the >= relation for a numeric VCL
// variable and a constant.
GreaterEqual
// Less specifies the < relation for a numeric VCL variable
// and a constant.
Less
// LessEqual specifies the <= relation for a numeric VCL
// variable and a constant.
LessEqual
)
// MatchTerm is a term describing the comparison of a VCL object with
......@@ -336,12 +351,18 @@ type MatchTerm struct {
Comparand string
Value string
Compare CompareType
Negate bool
}
func (match MatchTerm) hash(hash hash.Hash) {
hash.Write([]byte(match.Comparand))
hash.Write([]byte(match.Value))
hash.Write([]byte{byte(match.Compare)})
if match.Negate {
hash.Write([]byte{byte(1)})
} else {
hash.Write([]byte{byte(0)})
}
}
// interface for sorting []MatchTerm
......@@ -446,19 +467,6 @@ const (
Delete
)
// RewriteCompare classifies the comparison operation used to evaluate
// the conditions for a rewrite.
type RewriteCompare uint8
const (
// RewriteMatch means that a regex match is executed.
RewriteMatch RewriteCompare = iota
// RewriteEqual means that fixed strings are tested for equality.
RewriteEqual
// Prefix indicates a fixed-string prefix match.
Prefix
)
// SubType classifies the VCL subroutine in which a rewrite is
// executed.
type SubType uint8
......@@ -625,7 +633,8 @@ type Rewrite struct {
Target string
Source string
Method MethodType
Compare RewriteCompare
Compare CompareType
Negate bool
VCLSub SubType
Select SelectType
}
......@@ -640,6 +649,11 @@ func (rw Rewrite) hash(hash hash.Hash) {
hash.Write([]byte(rw.Source))
hash.Write([]byte{byte(rw.Method)})
hash.Write([]byte{byte(rw.Compare)})
if rw.Negate {
hash.Write([]byte{byte(1)})
} else {
hash.Write([]byte{byte(0)})
}
hash.Write([]byte{byte(rw.VCLSub)})
hash.Write([]byte{byte(rw.Select)})
}
......@@ -651,36 +665,6 @@ func (a byVCLSub) Len() int { return len(a) }
func (a byVCLSub) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a byVCLSub) Less(i, j int) bool { return a[i].VCLSub < a[j].VCLSub }
// ReqCompareType classifies comparison operations performed for the
// Conditions in a request disposition specification. The relation may
// be negated, if the Negate field in Condition is true.
type ReqCompareType uint8
const (
// ReqEqual specifies equality -- string equality, numeric
// equality, or membership in a set of fixed strings.
ReqEqual ReqCompareType = iota
// ReqMatch specifies a regular expression match.
ReqMatch
// ReqPrefix specifies that a string has a prefix in a set of
// fixed strings.
ReqPrefix
// Exists specifies that a request header exists.
Exists
// Greater specifies the > relation between a VCL variable
// with a numeric value and a constant.
Greater
// GreaterEqual specifies the >= relation for a numeric VCL
// variable and a constant.
GreaterEqual
// Less specifies the < relation for a numeric VCL variable
// and a constant.
Less
// LessEqual specifies the <= relation for a numeric VCL
// variable and a constant.
LessEqual
)
// Condition specifies (one of) the conditions that must be true if a
// client request disposition is to be executed.
type Condition struct {
......@@ -688,7 +672,7 @@ type Condition struct {
MatchFlags MatchFlagsType
Count *uint
Comparand string
Compare ReqCompareType
Compare CompareType
Negate bool
}
......
......@@ -47,24 +47,22 @@ var fMap = template.FuncMap{
"dirType": func(svc Service) string { return dirType(svc) },
"rewrName": func(i int) string { return rewrName(i) },
"needsMatcher": func(rewr Rewrite) bool { return needsMatcher(rewr) },
"rewrVMOD": func(rewr Rewrite) string { return rewrVMOD(rewr) },
"rewrFlags": func(rewr Rewrite) string { return rewrFlags(rewr) },
"needsSave": func(rewr Rewrite) bool { return needsSave(rewr) },
"needsCompile": func(rewr Rewrite) bool { return needsCompile(rewr) },
"rewrSub": func(rewr Rewrite) string { return rewrSub(rewr) },
"rewrMatch": func(rewr Rewrite) string { return rewrMatch(rewr) },
"rewrOp": func(rewr Rewrite) string { return rewrOp(rewr) },
"rewrSelect": func(rewr Rewrite) string { return rewrSelect(rewr) },
"reqVMOD": func(cond Condition) string { return reqVMOD(cond) },
"reqMatch": func(cond Condition) string { return reqMatch(cond) },
"value": func(cond Condition) string { return reqValue(cond) },
"reqFlags": func(cond Condition) string { return reqFlags(cond) },
"exists": func(cmp ReqCompareType) bool { return cmp == Exists },
"needsCompile": func(cmp CompareType) bool { return cmp == Match },
"exists": func(cmp CompareType) bool { return cmp == Exists },
"match": func(cmp CompareType) string { return match(cmp) },
"vmod": func(cmp CompareType) string { return vmod(cmp) },
"aclCmp": func(comparand string) string {
return aclCmp(comparand)
},
"cmpRelation": func(cmp CompareType) string {
return cmpRelation(cmp)
"cmpRelation": func(cmp CompareType, negate bool) string {
return cmpRelation(cmp, negate)
},
"backendName": func(svc Service, addr string) string {
return backendName(svc, addr)
......@@ -97,7 +95,7 @@ var fMap = template.FuncMap{
return rewr.Method == Replace
},
"needsRegex": func(rewr Rewrite) bool {
return rewr.Compare != RewriteMatch &&
return rewr.Compare != Match &&
(rewr.Method == Sub || rewr.Method == Suball)
},
"saveRegex": func(rewr Rewrite, rule RewriteRule) string {
......@@ -108,11 +106,10 @@ var fMap = template.FuncMap{
return regex + "$"
},
"needsAll": func(rewr Rewrite) bool {
return rewr.Compare != RewriteMatch && rewr.Method == Suball
return rewr.Compare != Match && rewr.Method == Suball
},