Add multiple values to headers
Use the headersToAppend
capability to add multiple values to the same header.
In this guide, you explore how to use the headersToAppend
transformation template attribute to add multiple values to the same header. The values are separated with a comma.
This guide uses a subset of the supported transformation template attributes. To review all the attributes that you can set, see Templating language.
Before you begin
Follow the Get started guide to install Gloo Gateway, set up a gateway resource, and deploy the httpbin sample app.
Get the external address of the gateway and save it in an environment variable.
Add multiple values to headers
Create a RouteOption or VirtualHostOption resource with the following transformation rules:
- Extract the value of the
Host
request header and use this value to build thecustomcookie2
string. Then, append the transformed string to theSet-Cookie
request header. - Extract the value of the
Host
request header and use this value to build thecustomcookie3
string. Then, append the transformed string to the sameSet-Cookie
request header.
- Extract the value of the
Send a request to the httpbin app. Verify that you see multiple values in the
Set-Cookie
request header.Example output:
{ "headers": { "Accept": [ "*/*" ], "Host": [ "www.example.com:8080" ], "Set-Cookie": [ "customcookie2=www.example.com:8080", "customcookie3=www.example.com:8080" ], "User-Agent": [ "curl/8.7.1" ], "X-Envoy-Expected-Rq-Timeout-Ms": [ "15000" ], "X-Forwarded-Proto": [ "http" ], "X-Request-Id": [ "09fbe5ed-5060-4cf5-835c-46729bf100db" ] } }
Cleanup
You can remove the resources that you created in this guide.
kubectl delete virtualhostoption transformation -n gloo-system
kubectl delete routeoption transformation -n httpbin