Skip to content

Commit d60959e

Browse files
authored
Adds support for treating missing headers as empty (#5584)
`TreatMissingHeadersAsEmpty` specifies if the header match rule specified header does not exist, this header value will be treated as empty. Defaults to false. Unlike the underlying Envoy implementation this is **only** supported for negative matches (e.g. NotContains, NotExact). The reason that I implemented only for negative matches is that is substantially simpler to reason about. I am open to implementing it for all cases if you think it is going to be useful. Signed-off-by: Sotiris Nanopoulos <[email protected]>
1 parent 12d07e7 commit d60959e

File tree

18 files changed

+631
-90
lines changed

18 files changed

+631
-90
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ generate-crd-yaml:
256256
generate-gateway-yaml:
257257
@echo "Generating Gateway API CRD YAML documents..."
258258
@GATEWAY_API_VERSION=$(GATEWAY_API_VERSION) ./hack/generate-gateway-yaml.sh
259-
259+
260260

261261
.PHONY: generate-api-docs
262262
generate-api-docs:
@@ -306,7 +306,7 @@ setup-kind-cluster: ## Make a kind cluster for testing
306306
install-contour-working: | setup-kind-cluster ## Install the local working directory version of Contour into a kind cluster
307307
./test/scripts/install-contour-working.sh
308308

309-
.PHONY: install-contour-release
309+
.PHONY: install-contour-release
310310
install-contour-release: | setup-kind-cluster ## Install the release version of Contour in CONTOUR_UPGRADE_FROM_VERSION, defaults to latest
311311
./test/scripts/install-contour-release.sh $(CONTOUR_UPGRADE_FROM_VERSION)
312312

apis/projectcontour/v1/httpproxy.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ type MatchCondition struct {
9090
// HeaderMatchCondition specifies how to conditionally match against HTTP
9191
// headers. The Name field is required, only one of Present, NotPresent,
9292
// Contains, NotContains, Exact, NotExact and Regex can be set.
93+
// For negative matching rules only (e.g. NotContains or NotExact) you can set
94+
// TreatMissingAsEmpty.
9395
// IgnoreCase has no effect for Regex.
9496
type HeaderMatchCondition struct {
9597
// Name is the name of the header to match against. Name is required.
@@ -137,6 +139,13 @@ type HeaderMatchCondition struct {
137139
// value.
138140
// +optional
139141
Regex string `json:"regex,omitempty"`
142+
143+
// TreatMissingAsEmpty specifies if the header match rule specified header
144+
// does not exist, this header value will be treated as empty. Defaults to false.
145+
// Unlike the underlying Envoy implementation this is **only** supported for
146+
// negative matches (e.g. NotContains, NotExact).
147+
// +optional
148+
TreatMissingAsEmpty bool `json:"treatMissingAsEmpty,omitempty"`
140149
}
141150

142151
// QueryParameterMatchCondition specifies how to conditionally match against HTTP
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## Adds support for treating missing headers as empty when they are not present as part of header matching
2+
3+
`TreatMissingAsEmpty` specifies if the header match rule specified header does not exist, this header value will be treated as empty. Defaults to false.
4+
Unlike the underlying Envoy implementation this is **only** supported for negative matches (e.g. NotContains, NotExact).

examples/contour/01-crds.yaml

Lines changed: 75 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,10 @@ spec:
727727
headers. The Name field is required, only
728728
one of Present, NotPresent, Contains,
729729
NotContains, Exact, NotExact and Regex
730-
can be set. IgnoreCase has no effect for
731-
Regex.
730+
can be set. For negative matching rules
731+
only (e.g. NotContains or NotExact) you
732+
can set TreatMissingAsEmpty. IgnoreCase
733+
has no effect for Regex.
732734
properties:
733735
contains:
734736
description: Contains specifies a substring
@@ -783,6 +785,16 @@ spec:
783785
expression pattern that must match
784786
the header value.
785787
type: string
788+
treatMissingAsEmpty:
789+
description: TreatMissingAsEmpty specifies
790+
if the header match rule specified
791+
header does not exist, this header
792+
value will be treated as empty. Defaults
793+
to false. Unlike the underlying Envoy
794+
implementation this is **only** supported
795+
for negative matches (e.g. NotContains,
796+
NotExact).
797+
type: boolean
786798
required:
787799
- name
788800
type: object
@@ -4121,8 +4133,10 @@ spec:
41214133
HTTP headers. The Name field is required,
41224134
only one of Present, NotPresent, Contains,
41234135
NotContains, Exact, NotExact and Regex
4124-
can be set. IgnoreCase has no effect
4125-
for Regex.
4136+
can be set. For negative matching
4137+
rules only (e.g. NotContains or NotExact)
4138+
you can set TreatMissingAsEmpty. IgnoreCase
4139+
has no effect for Regex.
41264140
properties:
41274141
contains:
41284142
description: Contains specifies
@@ -4180,6 +4194,17 @@ spec:
41804194
expression pattern that must match
41814195
the header value.
41824196
type: string
4197+
treatMissingAsEmpty:
4198+
description: TreatMissingAsEmpty
4199+
specifies if the header match
4200+
rule specified header does not
4201+
exist, this header value will
4202+
be treated as empty. Defaults
4203+
to false. Unlike the underlying
4204+
Envoy implementation this is **only**
4205+
supported for negative matches
4206+
(e.g. NotContains, NotExact).
4207+
type: boolean
41834208
required:
41844209
- name
41854210
type: object
@@ -4978,6 +5003,14 @@ spec:
49785003
description: Regex specifies a regular expression
49795004
pattern that must match the header value.
49805005
type: string
5006+
treatMissingAsEmpty:
5007+
description: TreatMissingAsEmpty specifies if the
5008+
header match rule specified header does not exist,
5009+
this header value will be treated as empty. Defaults
5010+
to false. Unlike the underlying Envoy implementation
5011+
this is **only** supported for negative matches
5012+
(e.g. NotContains, NotExact).
5013+
type: boolean
49815014
required:
49825015
- name
49835016
type: object
@@ -5140,6 +5173,14 @@ spec:
51405173
description: Regex specifies a regular expression
51415174
pattern that must match the header value.
51425175
type: string
5176+
treatMissingAsEmpty:
5177+
description: TreatMissingAsEmpty specifies if the
5178+
header match rule specified header does not exist,
5179+
this header value will be treated as empty. Defaults
5180+
to false. Unlike the underlying Envoy implementation
5181+
this is **only** supported for negative matches
5182+
(e.g. NotContains, NotExact).
5183+
type: boolean
51435184
required:
51445185
- name
51455186
type: object
@@ -5670,8 +5711,10 @@ spec:
56705711
is required, only one of Present,
56715712
NotPresent, Contains, NotContains,
56725713
Exact, NotExact and Regex can be
5673-
set. IgnoreCase has no effect for
5674-
Regex.
5714+
set. For negative matching rules
5715+
only (e.g. NotContains or NotExact)
5716+
you can set TreatMissingAsEmpty.
5717+
IgnoreCase has no effect for Regex.
56755718
properties:
56765719
contains:
56775720
description: Contains specifies
@@ -5732,6 +5775,17 @@ spec:
57325775
regular expression pattern that
57335776
must match the header value.
57345777
type: string
5778+
treatMissingAsEmpty:
5779+
description: TreatMissingAsEmpty
5780+
specifies if the header match
5781+
rule specified header does not
5782+
exist, this header value will
5783+
be treated as empty. Defaults
5784+
to false. Unlike the underlying
5785+
Envoy implementation this is
5786+
**only** supported for negative
5787+
matches (e.g. NotContains, NotExact).
5788+
type: boolean
57355789
required:
57365790
- name
57375791
type: object
@@ -7039,8 +7093,10 @@ spec:
70397093
HTTP headers. The Name field is required,
70407094
only one of Present, NotPresent, Contains,
70417095
NotContains, Exact, NotExact and Regex
7042-
can be set. IgnoreCase has no effect
7043-
for Regex.
7096+
can be set. For negative matching
7097+
rules only (e.g. NotContains or NotExact)
7098+
you can set TreatMissingAsEmpty. IgnoreCase
7099+
has no effect for Regex.
70447100
properties:
70457101
contains:
70467102
description: Contains specifies
@@ -7098,6 +7154,17 @@ spec:
70987154
expression pattern that must match
70997155
the header value.
71007156
type: string
7157+
treatMissingAsEmpty:
7158+
description: TreatMissingAsEmpty
7159+
specifies if the header match
7160+
rule specified header does not
7161+
exist, this header value will
7162+
be treated as empty. Defaults
7163+
to false. Unlike the underlying
7164+
Envoy implementation this is **only**
7165+
supported for negative matches
7166+
(e.g. NotContains, NotExact).
7167+
type: boolean
71017168
required:
71027169
- name
71037170
type: object

0 commit comments

Comments
 (0)