This is a demo to show how to overwrite / append HTTP headers to request.
- Return a
text/plain
response which contains all HTTP request headers. - Any request to
/overwrite
whichContent-Type
header will be overwriten byapplication/json
.
Clone the resource config files and apply to the cluster.
Notice: In this sample, we use GKE for constructing kubernetes cluster. You should check your cluster provider supports use of ingress.
# Clone this repository
$ git clone https://github.com/ibara1454/k8s-overwrite-header-demo.git
# Change current directory to such repository
$ cd k8s-overwrite-header-demo
# Apply all resource config files (to current namespace)
$ kubectl apply -f .
Get the external IP address of cluster by using kubectl get ingress
.
$ kubectl get ingress
# NAME HOSTS ADDRESS PORTS AGE
# ingress * 130.211.***.*** 80 108s
Access to /
of the external IP. This is a normal pattern.
$ curl 130.211.***.*** | jq
# {
# "host": "node-clusterip",
# "connection": "close",
# "user-agent": "curl/7.58.0",
# "accept": "*/*"
# }
Access to /overwrite
of the external IP. You could see an additional "content-type": "application/json"
is appended.
$ curl 130.211.***.***/overwrite | jq
# {
# "content-type": "application/json",
# "host": "node-clusterip",
# "connection": "close",
# "user-agent": "curl/7.58.0",
# "accept": "*/*"
# }
After verification, you might want to delete all resources just by using kubectl delete
.
kubectl delete -f .
The MIT License (MIT). Copyright (c) 2020, Chiajun Wang