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
3 changes: 1 addition & 2 deletions api/v1alpha1/clienttrafficpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
)

Expand Down Expand Up @@ -159,7 +158,7 @@ type HeaderSettings struct {
// routing, tracing and built-in header manipulation.
//
// +optional
EarlyRequestHeaders *gwapiv1.HTTPHeaderFilter `json:"earlyRequestHeaders,omitempty"`
EarlyRequestHeaders *HTTPHeaderFilter `json:"earlyRequestHeaders,omitempty"`
}

// WithUnderscoresAction configures the action to take when an HTTP header with underscores
Expand Down
81 changes: 81 additions & 0 deletions api/v1alpha1/shared_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -871,3 +871,84 @@ type CustomRedirect struct {
// +kubebuilder:validation:Enum=301;302
StatusCode *int `json:"statusCode,omitempty"`
}

// HTTPHeaderFilter has been copied from the upstream Gateway API project
// https://github.com/kubernetes-sigs/gateway-api/blob/main/apis/v1/httproute_types.go
// and edited to increase the maxItems from 16 to 64
// Remove this definition and reuse the upstream one once it supports items more than 64

// HTTPHeaderFilter defines a filter that modifies the headers of an HTTP
// request or response. Only one action for a given header name is
// permitted. Filters specifying multiple actions of the same or different
// type for any one header name are invalid. Configuration to set or add
// multiple values for a header must use RFC 7230 header value formatting,
// separating each value with a comma.
type HTTPHeaderFilter struct {
// Set overwrites the request with the given header (name, value)
// before the action.
//
// Input:
// GET /foo HTTP/1.1
// my-header: foo
//
// Config:
// set:
// - name: "my-header"
// value: "bar"
//
// Output:
// GET /foo HTTP/1.1
// my-header: bar
//
// +optional
// +listType=map
// +listMapKey=name
// +kubebuilder:validation:MaxItems=64
Set []gwapiv1.HTTPHeader `json:"set,omitempty"`

// Add adds the given header(s) (name, value) to the request
// before the action. It appends to any existing values associated
// with the header name.
//
// Input:
// GET /foo HTTP/1.1
// my-header: foo
//
// Config:
// add:
// - name: "my-header"
// value: "bar,baz"
//
// Output:
// GET /foo HTTP/1.1
// my-header: foo,bar,baz
//
// +optional
// +listType=map
// +listMapKey=name
// +kubebuilder:validation:MaxItems=64
Add []gwapiv1.HTTPHeader `json:"add,omitempty"`

// Remove the given header(s) from the HTTP request before the action. The
// value of Remove is a list of HTTP header names. Note that the header
// names are case-insensitive (see
// https://datatracker.ietf.org/doc/html/rfc2616#section-4.2).
//
// Input:
// GET /foo HTTP/1.1
// my-header1: foo
// my-header2: bar
// my-header3: baz
//
// Config:
// remove: ["my-header1", "my-header3"]
//
// Output:
// GET /foo HTTP/1.1
// my-header2: bar
//
// +optional
// +listType=set
// +kubebuilder:validation:MaxItems=64
Remove []string `json:"remove,omitempty"`
}
32 changes: 31 additions & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ spec:
- name
- value
type: object
maxItems: 16
maxItems: 64
type: array
x-kubernetes-list-map-keys:
- name
Expand All @@ -270,7 +270,7 @@ spec:
my-header2: bar
items:
type: string
maxItems: 16
maxItems: 64
type: array
x-kubernetes-list-type: set
set:
Expand Down Expand Up @@ -318,7 +318,7 @@ spec:
- name
- value
type: object
maxItems: 16
maxItems: 64
type: array
x-kubernetes-list-map-keys:
- name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ spec:
- name
- value
type: object
maxItems: 16
maxItems: 64
type: array
x-kubernetes-list-map-keys:
- name
Expand All @@ -269,7 +269,7 @@ spec:
my-header2: bar
items:
type: string
maxItems: 16
maxItems: 64
type: array
x-kubernetes-list-type: set
set:
Expand Down Expand Up @@ -317,7 +317,7 @@ spec:
- name
- value
type: object
maxItems: 16
maxItems: 64
type: array
x-kubernetes-list-map-keys:
- name
Expand Down
3 changes: 1 addition & 2 deletions internal/gatewayapi/clienttrafficpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/utils/ptr"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"

egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
Expand Down Expand Up @@ -983,7 +982,7 @@ func buildConnection(connection *egv1a1.ClientConnection) (*ir.ClientConnection,
return irConnection, nil
}

func translateEarlyRequestHeaders(headerModifier *gwapiv1.HTTPHeaderFilter) ([]ir.AddHeader, []string, error) {
func translateEarlyRequestHeaders(headerModifier *egv1a1.HTTPHeaderFilter) ([]ir.AddHeader, []string, error) {
// Make sure the header modifier config actually exists
if headerModifier == nil {
return nil, nil, nil
Expand Down
21 changes: 21 additions & 0 deletions site/content/en/latest/api/extension_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -2280,6 +2280,27 @@ _Appears in:_
| `headersToBackend` | _string array_ | false | | HeadersToBackend are the authorization response headers that will be added<br />to the original client request before sending it to the backend server.<br />Note that coexisting headers will be overridden.<br />If not specified, no authorization response headers will be added to the<br />original client request. |


#### HTTPHeaderFilter



HTTPHeaderFilter defines a filter that modifies the headers of an HTTP
request or response. Only one action for a given header name is
permitted. Filters specifying multiple actions of the same or different
type for any one header name are invalid. Configuration to set or add
multiple values for a header must use RFC 7230 header value formatting,
separating each value with a comma.

_Appears in:_
- [HeaderSettings](#headersettings)

| Field | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `set` | _HTTPHeader array_ | false | | Set overwrites the request with the given header (name, value)<br />before the action.<br />Input:<br /> GET /foo HTTP/1.1<br /> my-header: foo<br />Config:<br /> set:<br /> - name: "my-header"<br /> value: "bar"<br />Output:<br /> GET /foo HTTP/1.1<br /> my-header: bar |
| `add` | _HTTPHeader array_ | false | | Add adds the given header(s) (name, value) to the request<br />before the action. It appends to any existing values associated<br />with the header name.<br />Input:<br /> GET /foo HTTP/1.1<br /> my-header: foo<br />Config:<br /> add:<br /> - name: "my-header"<br /> value: "bar,baz"<br />Output:<br /> GET /foo HTTP/1.1<br /> my-header: foo,bar,baz |
| `remove` | _string array_ | false | | Remove the given header(s) from the HTTP request before the action. The<br />value of Remove is a list of HTTP header names. Note that the header<br />names are case-insensitive (see<br />https://datatracker.ietf.org/doc/html/rfc2616#section-4.2).<br />Input:<br /> GET /foo HTTP/1.1<br /> my-header1: foo<br /> my-header2: bar<br /> my-header3: baz<br />Config:<br /> remove: ["my-header1", "my-header3"]<br />Output:<br /> GET /foo HTTP/1.1<br /> my-header2: bar |


#### HTTPHostnameModifier


Expand Down
6 changes: 3 additions & 3 deletions test/helm/gateway-crds-helm/all.out.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20242,7 +20242,7 @@ spec:
- name
- value
type: object
maxItems: 16
maxItems: 64
type: array
x-kubernetes-list-map-keys:
- name
Expand All @@ -20268,7 +20268,7 @@ spec:
my-header2: bar
items:
type: string
maxItems: 16
maxItems: 64
type: array
x-kubernetes-list-type: set
set:
Expand Down Expand Up @@ -20316,7 +20316,7 @@ spec:
- name
- value
type: object
maxItems: 16
maxItems: 64
type: array
x-kubernetes-list-map-keys:
- name
Expand Down
6 changes: 3 additions & 3 deletions test/helm/gateway-crds-helm/envoy-gateway-crds.out.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2930,7 +2930,7 @@ spec:
- name
- value
type: object
maxItems: 16
maxItems: 64
type: array
x-kubernetes-list-map-keys:
- name
Expand All @@ -2956,7 +2956,7 @@ spec:
my-header2: bar
items:
type: string
maxItems: 16
maxItems: 64
type: array
x-kubernetes-list-type: set
set:
Expand Down Expand Up @@ -3004,7 +3004,7 @@ spec:
- name
- value
type: object
maxItems: 16
maxItems: 64
type: array
x-kubernetes-list-map-keys:
- name
Expand Down