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
49 changes: 48 additions & 1 deletion api/v1alpha1/shared_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,11 +662,14 @@ type HTTP2Settings struct {
}

// ResponseOverride defines the configuration to override specific responses with a custom one.
// +kubebuilder:validation:XValidation:rule="(has(self.response) && !has(self.redirect)) || (!has(self.response) && has(self.redirect))",message="exactly one of response or redirect must be specified"
type ResponseOverride struct {
// Match configuration.
Match CustomResponseMatch `json:"match"`
// Response configuration.
Response CustomResponse `json:"response"`
Response *CustomResponse `json:"response,omitempty"`
// Redirect configuration
Redirect *CustomRedirect `json:"redirect,omitempty"`
}

// CustomResponseMatch defines the configuration for matching a user response to return a custom one.
Expand Down Expand Up @@ -797,3 +800,47 @@ type Tracing struct {
// +optional
CustomTags map[string]CustomTag `json:"customTags,omitempty"`
}

// CustomRedirect contains configuration for returning a custom redirect.
type CustomRedirect struct {
// Scheme is the scheme to be used in the value of the `Location` header in
// the response. When empty, the scheme of the request is used.
//
// +optional
// +kubebuilder:validation:Enum=http;https
Scheme *string `json:"scheme,omitempty"`

// Hostname is the hostname to be used in the value of the `Location`
// header in the response.
// When empty, the hostname in the `Host` header of the request is used.
//
// +optional
Hostname *gwapiv1.PreciseHostname `json:"hostname,omitempty"`

// Path defines parameters used to modify the path of the incoming request.
// The modified path is then used to construct the `Location` header. When
// empty, the request path is used as-is.
//
// +optional
Path *gwapiv1.HTTPPathModifier `json:"path,omitempty"`

// Port is the port to be used in the value of the `Location`
// header in the response.
//
// If redirect scheme is not-empty, the well-known port associated with the redirect scheme will be used.
// Specifically "http" to port 80 and "https" to port 443. If the redirect scheme does not have a
// well-known port or redirect scheme is empty, the listener port of the Gateway will be used.
//
// Port will not be added in the 'Location' header if scheme is HTTP and port is 80
// or scheme is HTTPS and port is 443.
//
// +optional
Port *gwapiv1.PortNumber `json:"port,omitempty"`

// StatusCode is the HTTP status code to be used in response.
//
// +optional
// +kubebuilder:default=302
// +kubebuilder:validation:Enum=301;302
StatusCode *int `json:"statusCode,omitempty"`
}
51 changes: 50 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 @@ -1325,6 +1325,117 @@ spec:
required:
- statusCodes
type: object
redirect:
description: Redirect configuration
properties:
hostname:
description: |-
Hostname is the hostname to be used in the value of the `Location`
header in the response.
When empty, the hostname in the `Host` header of the request is used.
maxLength: 253
minLength: 1
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
type: string
path:
description: |-
Path defines parameters used to modify the path of the incoming request.
The modified path is then used to construct the `Location` header. When
empty, the request path is used as-is.
properties:
replaceFullPath:
description: |-
ReplaceFullPath specifies the value with which to replace the full path
of a request during a rewrite or redirect.
maxLength: 1024
type: string
replacePrefixMatch:
description: |-
ReplacePrefixMatch specifies the value with which to replace the prefix
match of a request during a rewrite or redirect. For example, a request
to "/foo/bar" with a prefix match of "/foo" and a ReplacePrefixMatch
of "/xyz" would be modified to "/xyz/bar".

Note that this matches the behavior of the PathPrefix match type. This
matches full path elements. A path element refers to the list of labels
in the path split by the `/` separator. When specified, a trailing `/` is
ignored. For example, the paths `/abc`, `/abc/`, and `/abc/def` would all
match the prefix `/abc`, but the path `/abcd` would not.

ReplacePrefixMatch is only compatible with a `PathPrefix` HTTPRouteMatch.
Using any other HTTPRouteMatch type on the same HTTPRouteRule will result in
the implementation setting the Accepted Condition for the Route to `status: False`.

Request Path | Prefix Match | Replace Prefix | Modified Path
maxLength: 1024
type: string
type:
description: |-
Type defines the type of path modifier. Additional types may be
added in a future release of the API.

Note that values may be added to this enum, implementations
must ensure that unknown values will not cause a crash.

Unknown values here must result in the implementation setting the
Accepted Condition for the Route to `status: False`, with a
Reason of `UnsupportedValue`.
enum:
- ReplaceFullPath
- ReplacePrefixMatch
type: string
required:
- type
type: object
x-kubernetes-validations:
- message: replaceFullPath must be specified when type is
set to 'ReplaceFullPath'
rule: 'self.type == ''ReplaceFullPath'' ? has(self.replaceFullPath)
: true'
- message: type must be 'ReplaceFullPath' when replaceFullPath
is set
rule: 'has(self.replaceFullPath) ? self.type == ''ReplaceFullPath''
: true'
- message: replacePrefixMatch must be specified when type
is set to 'ReplacePrefixMatch'
rule: 'self.type == ''ReplacePrefixMatch'' ? has(self.replacePrefixMatch)
: true'
- message: type must be 'ReplacePrefixMatch' when replacePrefixMatch
is set
rule: 'has(self.replacePrefixMatch) ? self.type == ''ReplacePrefixMatch''
: true'
port:
description: |-
Port is the port to be used in the value of the `Location`
header in the response.

If redirect scheme is not-empty, the well-known port associated with the redirect scheme will be used.
Specifically "http" to port 80 and "https" to port 443. If the redirect scheme does not have a
well-known port or redirect scheme is empty, the listener port of the Gateway will be used.

Port will not be added in the 'Location' header if scheme is HTTP and port is 80
or scheme is HTTPS and port is 443.
format: int32
maximum: 65535
minimum: 1
type: integer
scheme:
description: |-
Scheme is the scheme to be used in the value of the `Location` header in
the response. When empty, the scheme of the request is used.
enum:
- http
- https
type: string
statusCode:
default: 302
description: StatusCode is the HTTP status code to be used
in response.
enum:
- 301
- 302
type: integer
type: object
response:
description: Response configuration.
properties:
Expand Down Expand Up @@ -1406,8 +1517,11 @@ spec:
type: object
required:
- match
- response
type: object
x-kubernetes-validations:
- message: exactly one of response or redirect must be specified
rule: (has(self.response) && !has(self.redirect)) || (!has(self.response)
&& has(self.redirect))
type: array
retry:
description: |-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,117 @@ spec:
required:
- statusCodes
type: object
redirect:
description: Redirect configuration
properties:
hostname:
description: |-
Hostname is the hostname to be used in the value of the `Location`
header in the response.
When empty, the hostname in the `Host` header of the request is used.
maxLength: 253
minLength: 1
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
type: string
path:
description: |-
Path defines parameters used to modify the path of the incoming request.
The modified path is then used to construct the `Location` header. When
empty, the request path is used as-is.
properties:
replaceFullPath:
description: |-
ReplaceFullPath specifies the value with which to replace the full path
of a request during a rewrite or redirect.
maxLength: 1024
type: string
replacePrefixMatch:
description: |-
ReplacePrefixMatch specifies the value with which to replace the prefix
match of a request during a rewrite or redirect. For example, a request
to "/foo/bar" with a prefix match of "/foo" and a ReplacePrefixMatch
of "/xyz" would be modified to "/xyz/bar".

Note that this matches the behavior of the PathPrefix match type. This
matches full path elements. A path element refers to the list of labels
in the path split by the `/` separator. When specified, a trailing `/` is
ignored. For example, the paths `/abc`, `/abc/`, and `/abc/def` would all
match the prefix `/abc`, but the path `/abcd` would not.

ReplacePrefixMatch is only compatible with a `PathPrefix` HTTPRouteMatch.
Using any other HTTPRouteMatch type on the same HTTPRouteRule will result in
the implementation setting the Accepted Condition for the Route to `status: False`.

Request Path | Prefix Match | Replace Prefix | Modified Path
maxLength: 1024
type: string
type:
description: |-
Type defines the type of path modifier. Additional types may be
added in a future release of the API.

Note that values may be added to this enum, implementations
must ensure that unknown values will not cause a crash.

Unknown values here must result in the implementation setting the
Accepted Condition for the Route to `status: False`, with a
Reason of `UnsupportedValue`.
enum:
- ReplaceFullPath
- ReplacePrefixMatch
type: string
required:
- type
type: object
x-kubernetes-validations:
- message: replaceFullPath must be specified when type is
set to 'ReplaceFullPath'
rule: 'self.type == ''ReplaceFullPath'' ? has(self.replaceFullPath)
: true'
- message: type must be 'ReplaceFullPath' when replaceFullPath
is set
rule: 'has(self.replaceFullPath) ? self.type == ''ReplaceFullPath''
: true'
- message: replacePrefixMatch must be specified when type
is set to 'ReplacePrefixMatch'
rule: 'self.type == ''ReplacePrefixMatch'' ? has(self.replacePrefixMatch)
: true'
- message: type must be 'ReplacePrefixMatch' when replacePrefixMatch
is set
rule: 'has(self.replacePrefixMatch) ? self.type == ''ReplacePrefixMatch''
: true'
port:
description: |-
Port is the port to be used in the value of the `Location`
header in the response.

If redirect scheme is not-empty, the well-known port associated with the redirect scheme will be used.
Specifically "http" to port 80 and "https" to port 443. If the redirect scheme does not have a
well-known port or redirect scheme is empty, the listener port of the Gateway will be used.

Port will not be added in the 'Location' header if scheme is HTTP and port is 80
or scheme is HTTPS and port is 443.
format: int32
maximum: 65535
minimum: 1
type: integer
scheme:
description: |-
Scheme is the scheme to be used in the value of the `Location` header in
the response. When empty, the scheme of the request is used.
enum:
- http
- https
type: string
statusCode:
default: 302
description: StatusCode is the HTTP status code to be used
in response.
enum:
- 301
- 302
type: integer
type: object
response:
description: Response configuration.
properties:
Expand Down Expand Up @@ -1405,8 +1516,11 @@ spec:
type: object
required:
- match
- response
type: object
x-kubernetes-validations:
- message: exactly one of response or redirect must be specified
rule: (has(self.response) && !has(self.redirect)) || (!has(self.response)
&& has(self.redirect))
type: array
retry:
description: |-
Expand Down
Loading