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

add http-request del-header #106

Merged
merged 1 commit into from
Dec 3, 2024
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
22 changes: 22 additions & 0 deletions apis/config/v1alpha1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,8 @@ type HTTPRequestRules struct {
SetPath []HTTPPathRule `json:"setPath,omitempty"`
// AddHeader appends HTTP header fields
AddHeader []HTTPHeaderRule `json:"addHeader,omitempty"`
// DelHeader removes all HTTP header fields
DelHeader []HTTPDeleteHeaderRule `json:"delHeader,omitempty"`
// Redirect performs an HTTP redirection based on a redirect rule.
// +optional
Redirect []Redirect `json:"redirect,omitempty"`
Expand Down Expand Up @@ -804,6 +806,17 @@ func (h *HTTPRequestRules) Model() (models.HTTPRequestRules, error) {
})
}

for idx, header := range h.DelHeader {
model = append(model, &models.HTTPRequestRule{
Type: "del-header",
Index: ptr.To(int64(idx)),
HdrName: header.Name,
HdrMethod: header.Method,
Cond: header.ConditionType,
CondTest: header.Condition,
})
}

for idx, header := range h.ReplacePath {
model = append(model, &models.HTTPRequestRule{
Type: "replace-path",
Expand Down Expand Up @@ -948,6 +961,15 @@ type HTTPHeaderRule struct {
Value HTTPHeaderValue `json:"value"`
}

type HTTPDeleteHeaderRule struct {
Rule `json:",inline"`
// Name specifies the header name
Name string `json:"name"`
// Method is the matching applied on the header name
// +kubebuilder:validation:Enum=str;beg;end;sub;reg
Method string `json:"method"`
}

type HTTPPathRule struct {
Rule `json:",inline"`
// Value specifies the path value
Expand Down
11 changes: 11 additions & 0 deletions apis/config/v1alpha1/listen_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ var _ = Describe("Listen", Label("type"), func() {
},
},
},
DelHeader: []configv1alpha1.HTTPDeleteHeaderRule{
{
Name: "regex",
Method: "str",
},
{
Name: "Proxy",
},
},
},
},
},
Expand All @@ -133,6 +142,8 @@ var _ = Describe("Listen", Label("type"), func() {
Ω(p.String()).Should(ContainSubstring("http-request add-header X-Forwarded-Proto https"))
Ω(p.String()).Should(ContainSubstring("http-request add-header X-Forwarded-Proto-Version \"${PROTO_VERSION}\""))
Ω(p.String()).Should(ContainSubstring("http-request set-path /metrics if !{ ssl_fc }"))
Ω(p.String()).Should(ContainSubstring("http-request del-header Proxy"))
Ω(p.String()).Should(ContainSubstring("http-request del-header regex -m str"))
Ω(p.String()).Should(ContainSubstring("http-response set-header Strict-Transport-Security max-age=16000000; includeSubDomains; preload; if !{ ssl_fc }"))
})
It("should create binds", func() {
Expand Down
21 changes: 21 additions & 0 deletions apis/config/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions helm/haproxy-operator/crds/config.haproxy.com_backends.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,38 @@ spec:
- value
type: object
type: array
delHeader:
description: DelHeader removes all HTTP header fields
items:
properties:
condition:
description: Condition is a condition composed of ACLs.
type: string
conditionType:
description: ConditionType specifies the type of the condition
matching ('if' or 'unless')
enum:
- if
- unless
type: string
method:
description: Method is the matching applied on the header
name
enum:
- str
- beg
- end
- sub
- reg
type: string
name:
description: Name specifies the header name
type: string
required:
- method
- name
type: object
type: array
deny:
description: |-
Deny stops the evaluation of the rules and immediately rejects the request and emits an HTTP 403 error.
Expand Down
32 changes: 32 additions & 0 deletions helm/haproxy-operator/crds/config.haproxy.com_frontends.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,38 @@ spec:
- value
type: object
type: array
delHeader:
description: DelHeader removes all HTTP header fields
items:
properties:
condition:
description: Condition is a condition composed of ACLs.
type: string
conditionType:
description: ConditionType specifies the type of the condition
matching ('if' or 'unless')
enum:
- if
- unless
type: string
method:
description: Method is the matching applied on the header
name
enum:
- str
- beg
- end
- sub
- reg
type: string
name:
description: Name specifies the header name
type: string
required:
- method
- name
type: object
type: array
deny:
description: |-
Deny stops the evaluation of the rules and immediately rejects the request and emits an HTTP 403 error.
Expand Down
32 changes: 32 additions & 0 deletions helm/haproxy-operator/crds/config.haproxy.com_listens.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,38 @@ spec:
- value
type: object
type: array
delHeader:
description: DelHeader removes all HTTP header fields
items:
properties:
condition:
description: Condition is a condition composed of ACLs.
type: string
conditionType:
description: ConditionType specifies the type of the condition
matching ('if' or 'unless')
enum:
- if
- unless
type: string
method:
description: Method is the matching applied on the header
name
enum:
- str
- beg
- end
- sub
- reg
type: string
name:
description: Name specifies the header name
type: string
required:
- method
- name
type: object
type: array
deny:
description: |-
Deny stops the evaluation of the rules and immediately rejects the request and emits an HTTP 403 error.
Expand Down
Loading