8000 Add support for Envoy CustomResponse LocalReply in HTTPProxy CRDs by usiegj00 · Pull Request #6974 · projectcontour/contour · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add support for Envoy CustomResponse LocalReply in HTTPProxy CRDs #6974

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
93 changes: 93 additions & 0 deletions apis/projectcontour/v1/httpproxy.go
8000
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,10 @@ type Route struct {
// Only one of IPAllowFilterPolicy and IPDenyFilterPolicy can be defined.
// The rules defined here override any rules set on the root HTTPProxy.
IPDenyFilterPolicy []IPFilterPolicy `json:"ipDenyPolicy,omitempty"`

// ResponseOverridePolicy defines how to override responses from backends based on status codes.
// +optional
ResponseOverridePolicy []HTTPResponseOverridePolicy `json:"responseOverridePolicy,omitempty"`
}

type JWTVerificationPolicy struct {
Expand Down Expand Up @@ -684,6 +688,95 @@ type HTTPDirectResponsePolicy struct {
Body string `json:"body,omitempty"`
}

// StatusCodeType defines the type of status code match in HTTPResponseOverridePolicy
// +kubebuilder:validation:Enum=Value;Range
type StatusCodeType string

// StatusCodeValue defines a single status code to match
type StatusCodeValue struct {
// Value is the exact status code to match
// +kubebuilder:validation:Minimum=100
// +kubebuilder:validation:Maximum=599
// +required
Value int `json:"value"`
}

// StatusCodeRange defines a range of status codes to match
type StatusCodeRange struct {
// Start is the beginning of the status code range (inclusive)
// +kubebuilder:validation:Minimum=100
// +kubebuilder:validation:Maximum=599
// +required
Start int `json:"start"`

// End is the end of the status code range (inclusive)
// +kubebuilder:validation:Minimum=100
// +kubebuilder:validation:Maximum=599
// +required
End int `json:"end"`
}

// StatusCodeMatch defines a status code match condition
type StatusCodeMatch struct {
// Type specifies how to match the status code
// +required
Type StatusCodeType `json:"type"`

// Value is used when Type is Value to specify an exact status code
// +optional
Value int `json:"value,omitempty"`

// Range is used when Type is Range to specify a range of status codes
// +optional
Range *StatusCodeRange `json:"range,omitempty"`
}

// ResponseBodyConfig defines the response body to use in response override
type ResponseBodyConfig struct {
// Type specifies the type of body content to be used
// +kubebuilder:validation:Enum=Inline
// +required
Type string `json:"type"`

// Inline provides the content directly in the HTTPProxy resource
// A 4KB size limit is enforced to balance having sufficiently expressive content
// for custom responses while avoiding overwhelming bloat in CRDs.
// +optional
// +kubebuilder:validation:MaxLength=4096
Inline string `json:"inline,omitempty"`
}

// ResponseOverrideMatch defines the conditions under which responses should be modified
type ResponseOverrideMatch struct {
// StatusCodes defines the HTTP status codes to match
// +required
// +kubebuilder:validation:MinItems=1
StatusCodes []StatusCodeMatch `json:"statusCodes"`
}

// ResponseOverrideResponse defines how the response should be modified
type ResponseOverrideResponse struct {
// ContentType defines the Content-Type header value
// If not specified, "text/plain" is used by default
// +optional
ContentType string `json:"contentType,omitempty"`

// Body defines the content of the response body
// +required
Body ResponseBodyConfig `json:"body"`
}

// HTTPResponseOverridePolicy defines configuration for overriding responses from backends based on status codes
type HTTPResponseOverridePolicy struct {
// Match defines the conditions under which the response should be overridden
// +required
Match ResponseOverrideMatch `json:"match"`

// Response defines how to override the response
// +required
Response ResponseOverrideResponse `json:"response"`
}

// HTTPRequestRedirectPolicy defines configuration for redirecting a request.
type HTTPRequestRedirectPolicy struct {
// Scheme is the scheme to be used in the value of the `Location`
Expand Down
127 changes: 127 additions & 0 deletions apis/projectcontour/v1/zz_generated.deepcopy.go

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

3 changes: 3 additions & 0 deletions changelogs/unreleased/6974-usiegj00-small.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Response Override Policy

Added support for response override policy in HTTPProxy, allowing users to customize response headers and status codes. See the [documentation](https://projectcontour.io/docs/mai 5D32 n/config/request-routing/#response-override-policy) for more details.
93 changes: 93 additions & 0 deletions examples/contour/01-crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6732,6 +6732,99 @@ spec:
type: object
type: array
type: object
responseOverridePolicy:
description: ResponseOverridePolicy defines how to override
responses from backends based on status codes.
items:
description: HTTPResponseOverridePolicy defines configuration
for overriding responses from backends based on status codes
properties:
match:
description: Match defines the conditions under which
the response should be overridden
properties:
statusCodes:
description: StatusCodes defines the HTTP status codes
to match
items:
description: StatusCodeMatch defines a status code
match condition
properties:
range:
description: Range is used when Type is Range
to specify a range of status codes
properties:
end:
description: End is the end of the status
code range (inclusive)
maximum: 599
minimum: 100
type: integer
start:
description: Start is the beginning of the
status code range (inclusive)
maximum: 599
minimum: 100
type: integer
required:
- end
- start
type: object
type:
description: Type specifies how to match the
status code
enum:
- Value
- Range
type: string
value:
description: Value is used when Type is Value
to specify an exact status code
type: integer
required:
- type
type: object
minItems: 1
type: array
required:
- statusCodes
type: object
response:
description: Response defines how to override the response
properties:
body:
description: Body defines the content of the response
body
properties:
inline:
description: |-
Inline provides the content directly in the HTTPProxy resource
A 4KB size limit is enforced to balance having sufficiently expressive content
for custom responses while avoiding overwhelming bloat in CRDs.
maxLength: 4096
type: string
type:
description: Type specifies the type of body content
to be used
enum:
- Inline
type: string
required:
- type
type: object
contentType:
description: |-
ContentType defines the Content-Type header value
If not specified, "text/plain" is used by default
type: string
required:
- body
type: object
required:
- match
- response
type: object
type: array
retryPolicy:
description: The retry policy for this route.
properties:
Expand Down
Loading
Loading
0