Skip to content

Commit

Permalink
api: direct response (#4334)
Browse files Browse the repository at this point in the history
* api: direct response

Relates to #2714

Signed-off-by: Arko Dasgupta <[email protected]>
  • Loading branch information
arkodg authored Oct 18, 2024
1 parent 7293b6c commit 5375cf0
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 6 deletions.
20 changes: 20 additions & 0 deletions api/v1alpha1/httproutefilter_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ type HTTPRouteFilter struct {
type HTTPRouteFilterSpec struct {
// +optional
URLRewrite *HTTPURLRewriteFilter `json:"urlRewrite,omitempty"`
// +optional
DirectResponse *HTTPDirectResponseFilter `json:"directResponse,omitempty"`
}

// HTTPURLRewriteFilter define rewrites of HTTP URL components such as path and host
Expand All @@ -49,6 +51,24 @@ type HTTPURLRewriteFilter struct {
Path *HTTPPathModifier `json:"path,omitempty"`
}

// HTTPDirectResponseFilter defines the configuration to return a fixed response.
type HTTPDirectResponseFilter struct {
// Content Type of the response. This will be set in the Content-Type header.
//
// +optional
ContentType *string `json:"contentType,omitempty"`

// Body of the Response
//
// +optional
Body *CustomResponseBody `json:"body,omitempty"`

// Status Code of the HTTP response
// If unset, defaults to 200.
// +optional
StatusCode *int `json:"statusCode,omitempty"`
}

// HTTPPathModifierType defines the type of path redirect or rewrite.
type HTTPPathModifierType string

Expand Down
4 changes: 3 additions & 1 deletion api/v1alpha1/shared_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,9 @@ type CustomResponse struct {
ContentType *string `json:"contentType,omitempty"`

// Body of the Custom Response
Body CustomResponseBody `json:"body"`
//
// +optional
Body *CustomResponseBody `json:"body,omitempty"`
}

// ResponseValueType defines the types of values for the response body supported by Envoy Gateway.
Expand Down
41 changes: 40 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 @@ -1035,8 +1035,6 @@ spec:
description: Content Type of the response. This will be
set in the Content-Type header.
type: string
required:
- body
type: object
required:
- match
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,66 @@ spec:
spec:
description: Spec defines the desired state of HTTPRouteFilter.
properties:
directResponse:
description: HTTPDirectResponseFilter defines the configuration to
return a fixed response.
properties:
body:
description: Body of the Response
properties:
inline:
description: Inline contains the value as an inline string.
type: string
type:
description: Type is the type of method to use to read the
body value.
enum:
- Inline
- ValueRef
type: string
valueRef:
description: |-
ValueRef contains the contents of the body
specified as a local object reference.
Only a reference to ConfigMap is supported.
properties:
group:
description: |-
Group is the group of the referent. For example, "gateway.networking.k8s.io".
When unspecified or empty string, core API group is inferred.
maxLength: 253
pattern: ^$|^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
type: string
kind:
description: Kind is kind of the referent. For example
"HTTPRoute" or "Service".
maxLength: 63
minLength: 1
pattern: ^[a-zA-Z]([-a-zA-Z0-9]*[a-zA-Z0-9])?$
type: string
name:
description: Name is the name of the referent.
maxLength: 253
minLength: 1
type: string
required:
- group
- kind
- name
type: object
required:
- type
type: object
contentType:
description: Content Type of the response. This will be set in
the Content-Type header.
type: string
statusCode:
description: |-
Status Code of the HTTP response
If unset, defaults to 200.
type: integer
type: object
urlRewrite:
description: HTTPURLRewriteFilter define rewrites of HTTP URL components
such as path and host
Expand Down
20 changes: 19 additions & 1 deletion site/content/en/latest/api/extension_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ _Appears in:_
| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `contentType` | _string_ | false | Content Type of the response. This will be set in the Content-Type header. |
| `body` | _[CustomResponseBody](#customresponsebody)_ | true | Body of the Custom Response |
| `body` | _[CustomResponseBody](#customresponsebody)_ | false | Body of the Custom Response |


#### CustomResponseBody
Expand All @@ -877,6 +877,7 @@ CustomResponseBody

_Appears in:_
- [CustomResponse](#customresponse)
- [HTTPDirectResponseFilter](#httpdirectresponsefilter)

| Field | Type | Required | Description |
| --- | --- | --- | --- |
Expand Down Expand Up @@ -1922,6 +1923,22 @@ _Appears in:_
| `idleTimeout` | _[Duration](https://gateway-api.sigs.k8s.io/reference/spec/#gateway.networking.k8s.io/v1.Duration)_ | false | IdleTimeout for an HTTP connection. Idle time is defined as a period in which there are no active requests in the connection.<br />Default: 1 hour. |


#### HTTPDirectResponseFilter



HTTPDirectResponseFilter defines the configuration to return a fixed response.

_Appears in:_
- [HTTPRouteFilterSpec](#httproutefilterspec)

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `contentType` | _string_ | false | Content Type of the response. This will be set in the Content-Type header. |
| `body` | _[CustomResponseBody](#customresponsebody)_ | false | Body of the Response |
| `statusCode` | _integer_ | false | Status Code of the HTTP response<br />If unset, defaults to 200. |


#### HTTPExtAuthService


Expand Down Expand Up @@ -2045,6 +2062,7 @@ _Appears in:_
| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `urlRewrite` | _[HTTPURLRewriteFilter](#httpurlrewritefilter)_ | false | |
| `directResponse` | _[HTTPDirectResponseFilter](#httpdirectresponsefilter)_ | false | |


#### HTTPStatus
Expand Down
20 changes: 19 additions & 1 deletion site/content/zh/latest/api/extension_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ _Appears in:_
| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `contentType` | _string_ | false | Content Type of the response. This will be set in the Content-Type header. |
| `body` | _[CustomResponseBody](#customresponsebody)_ | true | Body of the Custom Response |
| `body` | _[CustomResponseBody](#customresponsebody)_ | false | Body of the Custom Response |


#### CustomResponseBody
Expand All @@ -877,6 +877,7 @@ CustomResponseBody

_Appears in:_
- [CustomResponse](#customresponse)
- [HTTPDirectResponseFilter](#httpdirectresponsefilter)

| Field | Type | Required | Description |
| --- | --- | --- | --- |
Expand Down Expand Up @@ -1922,6 +1923,22 @@ _Appears in:_
| `idleTimeout` | _[Duration](https://gateway-api.sigs.k8s.io/reference/spec/#gateway.networking.k8s.io/v1.Duration)_ | false | IdleTimeout for an HTTP connection. Idle time is defined as a period in which there are no active requests in the connection.<br />Default: 1 hour. |


#### HTTPDirectResponseFilter



HTTPDirectResponseFilter defines the configuration to return a fixed response.

_Appears in:_
- [HTTPRouteFilterSpec](#httproutefilterspec)

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `contentType` | _string_ | false | Content Type of the response. This will be set in the Content-Type header. |
| `body` | _[CustomResponseBody](#customresponsebody)_ | false | Body of the Response |
| `statusCode` | _integer_ | false | Status Code of the HTTP response<br />If unset, defaults to 200. |


#### HTTPExtAuthService


Expand Down Expand Up @@ -2045,6 +2062,7 @@ _Appears in:_
| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `urlRewrite` | _[HTTPURLRewriteFilter](#httpurlrewritefilter)_ | false | |
| `directResponse` | _[HTTPDirectResponseFilter](#httpdirectresponsefilter)_ | false | |


#### HTTPStatus
Expand Down

0 comments on commit 5375cf0

Please sign in to comment.