Skip to content

Commit

Permalink
Adds support for treating missing headers as empty (#5584)
Browse files Browse the repository at this point in the history
`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]>
  • Loading branch information
davinci26 authored Jul 28, 2023
1 parent 12d07e7 commit d60959e
Show file tree
Hide file tree
Showing 18 changed files with 631 additions and 90 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ generate-crd-yaml:
generate-gateway-yaml:
@echo "Generating Gateway API CRD YAML documents..."
@GATEWAY_API_VERSION=$(GATEWAY_API_VERSION) ./hack/generate-gateway-yaml.sh


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

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

Expand Down
9 changes: 9 additions & 0 deletions apis/projectcontour/v1/httpproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ type MatchCondition struct {
// HeaderMatchCondition specifies how to conditionally match against HTTP
// headers. The Name field is required, only one of Present, NotPresent,
// Contains, NotContains, Exact, NotExact and Regex can be set.
// For negative matching rules only (e.g. NotContains or NotExact) you can set
// TreatMissingAsEmpty.
// IgnoreCase has no effect for Regex.
type HeaderMatchCondition struct {
// Name is the name of the header to match against. Name is required.
Expand Down Expand Up @@ -137,6 +139,13 @@ type HeaderMatchCondition struct {
// value.
// +optional
Regex string `json:"regex,omitempty"`

// TreatMissingAsEmpty 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).
// +optional
TreatMissingAsEmpty bool `json:"treatMissingAsEmpty,omitempty"`
}

// QueryParameterMatchCondition specifies how to conditionally match against HTTP
Expand Down
4 changes: 4 additions & 0 deletions changelogs/unreleased/5584-davinci26-minor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Adds support for treating missing headers as empty when they are not present as part of header matching

`TreatMissingAsEmpty` 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).
83 changes: 75 additions & 8 deletions examples/contour/01-crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -727,8 +727,10 @@ spec:
headers. The Name field is required, only
one of Present, NotPresent, Contains,
NotContains, Exact, NotExact and Regex
can be set. IgnoreCase has no effect for
Regex.
can be set. For negative matching rules
only (e.g. NotContains or NotExact) you
can set TreatMissingAsEmpty. IgnoreCase
has no effect for Regex.
properties:
contains:
description: Contains specifies a substring
Expand Down Expand Up @@ -783,6 +785,16 @@ spec:
expression pattern that must match
the header value.
type: string
treatMissingAsEmpty:
description: TreatMissingAsEmpty 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).
type: boolean
required:
- name
type: object
Expand Down Expand Up @@ -4121,8 +4133,10 @@ spec:
HTTP headers. The Name field is required,
only one of Present, NotPresent, Contains,
NotContains, Exact, NotExact and Regex
can be set. IgnoreCase has no effect
for Regex.
can be set. For negative matching
rules only (e.g. NotContains or NotExact)
you can set TreatMissingAsEmpty. IgnoreCase
has no effect for Regex.
properties:
contains:
description: Contains specifies
Expand Down Expand Up @@ -4180,6 +4194,17 @@ spec:
expression pattern that must match
the header value.
type: string
treatMissingAsEmpty:
description: TreatMissingAsEmpty
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).
type: boolean
required:
- name
type: object
Expand Down Expand Up @@ -4978,6 +5003,14 @@ spec:
description: Regex specifies a regular expression
pattern that must match the header value.
type: string
treatMissingAsEmpty:
description: TreatMissingAsEmpty 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).
type: boolean
required:
- name
type: object
Expand Down Expand Up @@ -5140,6 +5173,14 @@ spec:
description: Regex specifies a regular expression
pattern that must match the header value.
type: string
treatMissingAsEmpty:
description: TreatMissingAsEmpty 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).
type: boolean
required:
- name
type: object
Expand Down Expand Up @@ -5670,8 +5711,10 @@ spec:
is required, only one of Present,
NotPresent, Contains, NotContains,
Exact, NotExact and Regex can be
set. IgnoreCase has no effect for
Regex.
set. For negative matching rules
only (e.g. NotContains or NotExact)
you can set TreatMissingAsEmpty.
IgnoreCase has no effect for Regex.
properties:
contains:
description: Contains specifies
Expand Down Expand Up @@ -5732,6 +5775,17 @@ spec:
regular expression pattern that
must match the header value.
type: string
treatMissingAsEmpty:
description: TreatMissingAsEmpty
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).
type: boolean
required:
- name
type: object
Expand Down Expand Up @@ -7039,8 +7093,10 @@ spec:
HTTP headers. The Name field is required,
only one of Present, NotPresent, Contains,
NotContains, Exact, NotExact and Regex
can be set. IgnoreCase has no effect
for Regex.
can be set. For negative matching
rules only (e.g. NotContains or NotExact)
you can set TreatMissingAsEmpty. IgnoreCase
has no effect for Regex.
properties:
contains:
description: Contains specifies
Expand Down Expand Up @@ -7098,6 +7154,17 @@ spec:
expression pattern that must match
the header value.
type: string
treatMissingAsEmpty:
description: TreatMissingAsEmpty
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).
type: boolean
required:
- name
type: object
Expand Down
Loading

0 comments on commit d60959e

Please sign in to comment.