Skip to content

This is a demo to show how to overwrite / append HTTP headers to request.

License

Notifications You must be signed in to change notification settings

ibara1454/k8s-overwrite-header-demo

Repository files navigation

k8s-overwrite-header-demo

License: MIT GitHub issues open License: MIT

This is a demo to show how to overwrite / append HTTP headers to request.

Feature

  • Return a text/plain response which contains all HTTP request headers.
  • Any request to /overwrite which Content-Type header will be overwriten by application/json.

Usage

Applying resources

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 .

Verification

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": "*/*"
# }

Deleting resources

After verification, you might want to delete all resources just by using kubectl delete.

kubectl delete -f .

License

The MIT License (MIT). Copyright (c) 2020, Chiajun Wang

About

This is a demo to show how to overwrite / append HTTP headers to request.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages