Skip to content

Commit

Permalink
api: direct response
Browse files Browse the repository at this point in the history
Relates to envoyproxy#2714

Signed-off-by: Arko Dasgupta <[email protected]>
  • Loading branch information
arkodg committed Sep 26, 2024
1 parent 6eefb28 commit c124a28
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 6 deletions.
7 changes: 7 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 @@ -43,6 +45,11 @@ type HTTPURLRewriteFilter struct {
Path *HTTPPathModifier `json:"path,omitempty"`
}

// HTTPDirectResponseFilter defines the configuration to return a fixed response.
type HTTPDirectResponseFilter struct {
CustomResponse `json:",inline"`
}

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

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

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

// Status Code of the HTTP response
//
// +optional
StatusCode *string `json:"statusCode,omitempty"`
}

// ResponseValueType defines the types of values for the response body supported by Envoy Gateway.
Expand Down
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 @@ -1051,8 +1051,9 @@ spec:
description: Content Type of the response. This will be
set in the Content-Type header.
type: string
required:
- body
statusCode:
description: Status Code of the HTTP response
type: string
type: object
required:
- match
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,64 @@ 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 Custom 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
type: string
type: object
urlRewrite:
description: HTTPURLRewriteFilter define rewrites of HTTP URL components
such as path and host
Expand Down
22 changes: 21 additions & 1 deletion site/content/en/latest/api/extension_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -859,12 +859,14 @@ _Appears in:_
CustomResponse defines the configuration for returning a custom response.

_Appears in:_
- [HTTPDirectResponseFilter](#httpdirectresponsefilter)
- [ResponseOverride](#responseoverride)

| 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 |
| `statusCode` | _string_ | false | Status Code of the HTTP response |


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

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

| Field | Type | Required | Description |
| --- | --- | --- | --- |
Expand Down Expand Up @@ -1920,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 Custom Response |
| `statusCode` | _string_ | false | Status Code of the HTTP response |


#### HTTPExtAuthService


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


#### HTTPStatus
Expand Down
22 changes: 21 additions & 1 deletion site/content/zh/latest/api/extension_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -859,12 +859,14 @@ _Appears in:_
CustomResponse defines the configuration for returning a custom response.

_Appears in:_
- [HTTPDirectResponseFilter](#httpdirectresponsefilter)
- [ResponseOverride](#responseoverride)

| 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 |
| `statusCode` | _string_ | false | Status Code of the HTTP response |


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

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

| Field | Type | Required | Description |
| --- | --- | --- | --- |
Expand Down Expand Up @@ -1920,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 Custom Response |
| `statusCode` | _string_ | false | Status Code of the HTTP response |


#### HTTPExtAuthService


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


#### HTTPStatus
Expand Down

0 comments on commit c124a28

Please sign in to comment.