Skip to content
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

DO NOT MERGE #5467

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 40 additions & 0 deletions config/crd/bases/k8s.nginx.org_virtualserverroutes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@ spec:
type: string
code:
type: integer
headers:
items:
description: Header defines an HTTP Header.
properties:
name:
type: string
value:
type: string
type: object
type: array
type:
type: string
type: object
Expand Down Expand Up @@ -276,6 +286,16 @@ spec:
type: string
code:
type: integer
headers:
items:
description: Header defines an HTTP Header.
properties:
name:
type: string
value:
type: string
type: object
type: array
type:
type: string
type: object
Expand Down Expand Up @@ -383,6 +403,16 @@ spec:
type: string
code:
type: integer
headers:
items:
description: Header defines an HTTP Header.
properties:
name:
type: string
value:
type: string
type: object
type: array
type:
type: string
type: object
Expand Down Expand Up @@ -489,6 +519,16 @@ spec:
type: string
code:
type: integer
headers:
items:
description: Header defines an HTTP Header.
properties:
name:
type: string
value:
type: string
type: object
type: array
type:
type: string
type: object
Expand Down
40 changes: 40 additions & 0 deletions config/crd/bases/k8s.nginx.org_virtualservers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,16 @@ spec:
type: string
code:
type: integer
headers:
items:
description: Header defines an HTTP Header.
properties:
name:
type: string
value:
type: string
type: object
type: array
type:
type: string
type: object
Expand Down Expand Up @@ -338,6 +348,16 @@ spec:
type: string
code:
type: integer
headers:
items:
description: Header defines an HTTP Header.
properties:
name:
type: string
value:
type: string
type: object
type: array
type:
type: string
type: object
Expand Down Expand Up @@ -445,6 +465,16 @@ spec:
type: string
code:
type: integer
headers:
items:
description: Header defines an HTTP Header.
properties:
name:
type: string
value:
type: string
type: object
type: array
type:
type: string
type: object
Expand Down Expand Up @@ -551,6 +581,16 @@ spec:
type: string
code:
type: integer
headers:
items:
description: Header defines an HTTP Header.
properties:
name:
type: string
value:
type: string
type: object
type: array
type:
type: string
type: object
Expand Down
80 changes: 80 additions & 0 deletions deploy/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,16 @@ spec:
type: string
code:
type: integer
headers:
items:
description: Header defines an HTTP Header.
properties:
name:
type: string
value:
type: string
type: object
type: array
type:
type: string
type: object
Expand Down Expand Up @@ -1149,6 +1159,16 @@ spec:
type: string
code:
type: integer
headers:
items:
description: Header defines an HTTP Header.
properties:
name:
type: string
value:
type: string
type: object
type: array
type:
type: string
type: object
Expand Down Expand Up @@ -1256,6 +1276,16 @@ spec:
type: string
code:
type: integer
headers:
items:
description: Header defines an HTTP Header.
properties:
name:
type: string
value:
type: string
type: object
type: array
type:
type: string
type: object
Expand Down Expand Up @@ -1362,6 +1392,16 @@ spec:
type: string
code:
type: integer
headers:
items:
description: Header defines an HTTP Header.
properties:
name:
type: string
value:
type: string
type: object
type: array
type:
type: string
type: object
Expand Down Expand Up @@ -1772,6 +1812,16 @@ spec:
type: string
code:
type: integer
headers:
items:
description: Header defines an HTTP Header.
properties:
name:
type: string
value:
type: string
type: object
type: array
type:
type: string
type: object
Expand Down Expand Up @@ -1900,6 +1950,16 @@ spec:
type: string
code:
type: integer
headers:
items:
description: Header defines an HTTP Header.
properties:
name:
type: string
value:
type: string
type: object
type: array
type:
type: string
type: object
Expand Down Expand Up @@ -2007,6 +2067,16 @@ spec:
type: string
code:
type: integer
headers:
items:
description: Header defines an HTTP Header.
properties:
name:
type: string
value:
type: string
type: object
type: array
type:
type: string
type: object
Expand Down Expand Up @@ -2113,6 +2183,16 @@ spec:
type: string
code:
type: integer
headers:
items:
description: Header defines an HTTP Header.
properties:
name:
type: string
value:
type: string
type: object
type: array
type:
type: string
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,9 @@ return:
code: 200
type: text/plain
body: "Hello World\n"
headers:
- name: x-coffee
value: espresso
```

{{% table %}}
Expand All @@ -592,10 +595,27 @@ return:
|``code`` | The status code of the response. The allowed values are: ``2XX``, ``4XX`` or ``5XX``. The default is ``200``. | ``int`` | No |
|``type`` | The MIME type of the response. The default is ``text/plain``. | ``string`` | No |
|``body`` | The body of the response. Supports NGINX variables*. Variables must be enclosed in curly brackets. For example: ``Request is ${request_uri}\n``. | ``string`` | Yes |
|``headers`` | The custom headers of the response. | [Action.Return.Header](#actionreturnheader) | No |
{{% /table %}}

\* -- Supported NGINX variables: `$request_uri`, `$request_method`, `$request_body`, `$scheme`, `$http_`, `$args`, `$arg_`, `$cookie_`, `$host`, `$request_time`, `$request_length`, `$nginx_version`, `$pid`, `$connection`, `$remote_addr`, `$remote_port`, `$time_iso8601`, `$time_local`, `$server_addr`, `$server_port`, `$server_name`, `$server_protocol`, `$connections_active`, `$connections_reading`, `$connections_writing` and `$connections_waiting`.

### Action.Return.Header

The header defines an HTTP Header for a canned response in an errorPage:

```yaml
name: x-debug-original-statuses
value: ${upstream_status}
```

{{% table %}}
|Field | Description | Type | Required |
| ---| ---| ---| --- |
|``name`` | The name of the header. | ``string`` | Yes |
|``value`` | The value of the header. | ``string`` | Yes |
{{% /table %}}

### Action.Proxy

The proxy action passes requests to an upstream with the ability to modify the request/response (for example, rewrite the URI or modify the headers).
Expand Down
1 change: 1 addition & 0 deletions internal/configs/version2/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ type ReturnLocation struct {
Name string
DefaultType string
Return Return
Headers []Header
}

// SplitClient defines a split_clients.
Expand Down
3 changes: 3 additions & 0 deletions internal/configs/version2/nginx-plus.virtualserver.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@ server {
{{ range $l := $s.ReturnLocations }}
location {{ $l.Name }} {
default_type "{{ $l.DefaultType }}";
{{ range $h := $l.Headers }}
add_header {{ $h.Name }} "{{ $h.Value }}" always;
{{ end }}
# status code is ignored here, using 0
return 0 "{{ $l.Return.Text }}";
}
Expand Down
3 changes: 3 additions & 0 deletions internal/configs/version2/nginx.virtualserver.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ server {
{{ range $l := $s.ReturnLocations }}
location {{ $l.Name }} {
default_type "{{ $l.DefaultType }}";
{{ range $h := $l.Headers }}
add_header {{ $h.Name }} "{{ $h.Value }}" always;
{{ end }}
# status code is ignored here, using 0
return 0 "{{ $l.Return.Text }}";
}
Expand Down
10 changes: 10 additions & 0 deletions internal/configs/virtualserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2086,6 +2086,15 @@ func generateLocationForReturn(path string, locationSnippets []string, actionRet
code = 200
}

var headers []version2.Header

for _, h := range actionReturn.Headers {
headers = append(headers, version2.Header{
Name: h.Name,
Value: h.Value,
})
}

retLocName := fmt.Sprintf("@return_%d", retLocIndex)

return version2.Location{
Expand All @@ -2107,6 +2116,7 @@ func generateLocationForReturn(path string, locationSnippets []string, actionRet
Return: version2.Return{
Text: actionReturn.Body,
},
Headers: headers,
}
}

Expand Down