Skip to content

Commit

Permalink
docs: (envoyproxy#3137) show 'apply yaml' either from stdin, or from …
Browse files Browse the repository at this point in the history
…file using tabs

Signed-off-by: Eitan Suez <eitan@tetrate.io>
  • Loading branch information
Eitan Suez committed Apr 19, 2024
1 parent 2c4d385 commit e435ea4
Showing 1 changed file with 152 additions and 0 deletions.
152 changes: 152 additions & 0 deletions site/content/en/latest/tasks/traffic/http-request-headers.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ does not have the header configured by the filter, then that header will be adde
has the header configured by the filter, then the value of the header in the filter will be appended to the value of the
header in the request.

{{< tabpane text=true >}}
{{% tab header="Apply from stdin" %}}
```shell
cat <<EOF | kubectl apply -f -
apiVersion: gateway.networking.k8s.io/v1
Expand Down Expand Up @@ -54,6 +56,42 @@ spec:
value: "foo"
EOF
```
{{% /tab %}}
{{% tab header="Apply from file" %}}
Save and apply the following resource to your cluster:

```yaml
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: http-headers
spec:
parentRefs:
- name: eg
hostnames:
- headers.example
rules:
- matches:
- path:
type: PathPrefix
value: /
backendRefs:
- group: ""
kind: Service
name: backend
port: 3000
weight: 1
filters:
- type: RequestHeaderModifier
requestHeaderModifier:
add:
- name: "add-header"
value: "foo"
```
{{% /tab %}}
{{< /tabpane >}}
The HTTPRoute status should indicate that it has been accepted and is bound to the example Gateway.
Expand Down Expand Up @@ -107,6 +145,8 @@ will be added, but unlike [adding request headers](#adding-request-headers) whic
the request already contains it, setting a header will cause the value to be replaced by the value configured in the
filter.

{{< tabpane text=true >}}
{{% tab header="Apply from stdin" %}}
```shell
cat <<EOF | kubectl apply -f -
apiVersion: gateway.networking.k8s.io/v1
Expand Down Expand Up @@ -137,6 +177,41 @@ spec:
value: "foo"
EOF
```
{{% /tab %}}
{{% tab header="Apply from file" %}}
Save and apply the following resource to your cluster:

```yaml
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: http-headers
spec:
parentRefs:
- name: eg
hostnames:
- headers.example
rules:
- backendRefs:
- group: ""
kind: Service
name: backend
port: 3000
weight: 1
matches:
- path:
type: PathPrefix
value: /
filters:
- type: RequestHeaderModifier
requestHeaderModifier:
set:
- name: "set-header"
value: "foo"
```
{{% /tab %}}
{{< /tabpane >}}
Querying `headers.example/get` should result in a `200` response from the example Gateway and the output from the
example app should indicate that the upstream example app received the header `add-header` with the original value
Expand Down Expand Up @@ -178,6 +253,8 @@ will be added, but unlike [adding request headers](#adding-request-headers) whic
the request already contains it, setting a header will cause the value to be replaced by the value configured in the
filter.

{{< tabpane text=true >}}
{{% tab header="Apply from stdin" %}}
```shell
cat <<EOF | kubectl apply -f -
apiVersion: gateway.networking.k8s.io/v1
Expand Down Expand Up @@ -206,6 +283,39 @@ spec:
- "remove-header"
EOF
```
{{% /tab %}}
{{% tab header="Apply from file" %}}
Save and apply the following resource to your cluster:

```yaml
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: http-headers
spec:
parentRefs:
- name: eg
hostnames:
- headers.example
rules:
- matches:
- path:
type: PathPrefix
value: /
backendRefs:
- group: ""
name: backend
port: 3000
weight: 1
filters:
- type: RequestHeaderModifier
requestHeaderModifier:
remove:
- "remove-header"
```
{{% /tab %}}
{{< /tabpane >}}

Querying `headers.example/get` should result in a `200` response from the example Gateway and the output from the
example app should indicate that the upstream example app received the header `add-header`, but the header
Expand Down Expand Up @@ -243,6 +353,8 @@ $ curl -vvv --header "Host: headers.example" "http://${GATEWAY_HOST}/get" --head

Headers can be added/set/removed in a single filter on the same HTTPRoute and they will all perform as expected

{{< tabpane text=true >}}
{{% tab header="Apply from stdin" %}}
```shell
cat <<EOF | kubectl apply -f -
apiVersion: gateway.networking.k8s.io/v1
Expand Down Expand Up @@ -278,6 +390,46 @@ spec:
- "removed-header"
EOF
```
{{% /tab %}}
{{% tab header="Apply from file" %}}
Save and apply the following resource to your cluster:

```yaml
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: http-headers
spec:
parentRefs:
- name: eg
hostnames:
- headers.example
rules:
- matches:
- path:
type: PathPrefix
value: /
backendRefs:
- group: ""
kind: Service
name: backend
port: 3000
weight: 1
filters:
- type: RequestHeaderModifier
requestHeaderModifier:
add:
- name: "add-header-1"
value: "foo"
set:
- name: "set-header-1"
value: "bar"
remove:
- "removed-header"
```
{{% /tab %}}
{{< /tabpane >}}

[HTTPRoute]: https://gateway-api.sigs.k8s.io/api-types/httproute/
[HTTPRoute filters]: https://gateway-api.sigs.k8s.io/reference/spec/#gateway.networking.k8s.io/v1.HTTPRouteFilter
Expand Down

0 comments on commit e435ea4

Please sign in to comment.