-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for ResponseHeaderModifier for HTTPRouteRule objects (#1880)
Add support for ResponseHeaderModifier for HTTPRouteRule objects Problem: Users want to add, set, and remove response headers. Solution: Use add_header NGINX directive to support ResponseHeaderModifier. ---- Co-authored-by: kaihsun <[email protected]>
- Loading branch information
1 parent
0098b07
commit 4d0a3de
Showing
26 changed files
with
995 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# HTTP Response Headers | ||
|
||
This directory contains the YAML files used in the [HTTP Response Headers](https://docs.nginx.com/nginx-gateway-fabric/how-to/traffic-management/response-headers.md) guide. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
apiVersion: gateway.networking.k8s.io/v1 | ||
kind: Gateway | ||
metadata: | ||
name: gateway | ||
spec: | ||
gatewayClassName: nginx | ||
listeners: | ||
- name: http | ||
port: 80 | ||
protocol: HTTP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: headers | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: headers | ||
template: | ||
metadata: | ||
labels: | ||
app: headers | ||
spec: | ||
containers: | ||
- name: headers | ||
image: nginx | ||
ports: | ||
- containerPort: 8080 | ||
volumeMounts: | ||
- name: config-volume | ||
mountPath: /etc/nginx | ||
readOnly: true | ||
volumes: | ||
- name: config-volume | ||
configMap: | ||
name: headers-config | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: headers-config | ||
# yamllint disable rule:indentation | ||
data: | ||
nginx.conf: |- | ||
user nginx; | ||
worker_processes 1; | ||
pid /var/run/nginx.pid; | ||
events {} | ||
http { | ||
default_type text/plain; | ||
server { | ||
listen 8080; | ||
add_header X-Header-Unmodified "unmodified"; | ||
add_header X-Header-Add "add-to"; | ||
add_header X-Header-Set "overwrite"; | ||
add_header X-Header-Remove "remove"; | ||
return 200 "ok"; | ||
} | ||
} | ||
# yamllint enable rule:indentation | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: headers | ||
spec: | ||
ports: | ||
- port: 80 | ||
targetPort: 8080 | ||
protocol: TCP | ||
name: http | ||
selector: | ||
app: headers |
29 changes: 29 additions & 0 deletions
29
examples/http-response-header-filter/http-route-filters.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
apiVersion: gateway.networking.k8s.io/v1 | ||
kind: HTTPRoute | ||
metadata: | ||
name: headers | ||
spec: | ||
parentRefs: | ||
- name: gateway | ||
sectionName: http | ||
hostnames: | ||
- "cafe.example.com" | ||
rules: | ||
- matches: | ||
- path: | ||
type: PathPrefix | ||
value: /headers | ||
filters: | ||
- type: ResponseHeaderModifier | ||
responseHeaderModifier: | ||
set: | ||
- name: X-Header-Set | ||
value: overwritten-value | ||
add: | ||
- name: X-Header-Add | ||
value: this-is-the-appended-value | ||
remove: | ||
- X-Header-Remove | ||
backendRefs: | ||
- name: headers | ||
port: 80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
apiVersion: gateway.networking.k8s.io/v1 | ||
kind: HTTPRoute | ||
metadata: | ||
name: headers | ||
spec: | ||
parentRefs: | ||
- name: gateway | ||
sectionName: http | ||
hostnames: | ||
- "cafe.example.com" | ||
rules: | ||
- matches: | ||
- path: | ||
type: PathPrefix | ||
value: /headers | ||
backendRefs: | ||
- name: headers | ||
port: 80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.