Retain HTTP headers in requests sent to WSO2 API Manager and forward them to backend services.

Ramindu De Silva
2 min readNov 7, 2023

There can be headers that are sent with the API requests which are needed by the backend services to validate or use. By default, when a API request is received to API gateway, “accept”,”activityid”,”Connection”,”Host”,”User-Agent” headers will be sent by removing all other headers.

To retain some specific headers, it is needed to have a policy that can be attached to the request flow.

This policy can be API specific or global for all the APIs. Check on how to create a policy and upload to the API Manager using documentation.

In this scenario, we can use the following sequence which uses the Header mediator to read the header and preserve it when it sends it to the backend.

Once the file is available, drag and drop to the resource. This process will ask whether it is needed to be applied to all the resources as well.

Then the new API can be deployed and when invoking with the API with a request includes headers, the API manager will preserve the header and sent to the backend.

Sample request can be found as below. Here the the header to be persevered is username.

curl -X 'GET' 'https://localhost:8245/ecommerceapi/1.0.0/items?sellerId=-1' -H 'accept: */*' -H 'username: adam' -H 'Authorization: Bearer eyJ4***0EPh-nRAvxzKIP59Ezw' -k

Hope this small tutorial will guide you when you have to preserve HTTP headers when using WSO2 API Manager.

--

--