Sending the Actual User-Agent to the Backend : WSO2 API Manager.

Menaka Jayawardena
2 min readDec 2, 2017

--

Hi,

In this article we are going to talk about a simple trick in WSO2 API Manager. Let’s get started…. :-)

When invoking an API which is published through the WSO2 API Manager, here is the request that is actually sent to the back end.

[2017-11-24 23:43:34,716] DEBUG - headers http-outgoing-1 >> GET /RESTfulExample/rest/hello/name/get HTTP/1.1
[2017-11-24 23:43:34,717] DEBUG - headers http-outgoing-1 >> Host: 10.100.5.138:8080
[2017-11-24 23:43:34,717] DEBUG - headers http-outgoing-1 >> Connection: Keep-Alive
[2017-11-24 23:43:34,717] DEBUG - headers http-outgoing-1 >> User-Agent: Synapse-PT-HttpComponents-NIO

As you can see the user agent is set as Synapse-PT-HttpComponents-NIO which is the WSO2 API Gateway. Let’s take a look at the request that we sent.

[2017-11-24 23:43:34,708] DEBUG - headers http-incoming-2 >> GET /test/v1.0/get HTTP/1.1
[2017-11-24 23:43:34,709] DEBUG - headers http-incoming-2 >> Host: 10.100.5.138:8243
[2017-11-24 23:43:34,709] DEBUG - headers http-incoming-2 >> User-Agent: curl/7.47.0
[2017-11-24 23:43:34,709] DEBUG - headers http-incoming-2 >> Accept: text/html
[2017-11-24 23:43:34,709] DEBUG - headers http-incoming-2 >> Authorization: Bearer xxxxx

So, there you can see the actual User-Agent that invoke the api. That is a cURL.

What could we do to send the actual user agent to our backend?

It’s very simple as 1, 2, 3

  1. Open passthru-http.properties file in <APIM-HOME>/repository/conf in a text editor.
  2. Uncomment http.user.agent.preserve and set the value to true.
  3. Save the file and restart the server…

Done.

So next time when invoke the api, here is the result we got…

[2017-11-28 17:10:40,680] DEBUG - headers http-outgoing-1 >> GET /RESTfulExample/rest/hello/name/get HTTP/1.1
[2017-11-28 17:10:40,680] DEBUG - headers http-outgoing-1 >> Accept: application/json
[2017-11-28 17:10:40,680] DEBUG - headers http-outgoing-1 >> User-Agent: curl/7.47.0
[2017-11-28 17:10:40,680] DEBUG - headers http-outgoing-1 >> Host: 10.100.5.138:8080
[2017-11-28 17:10:40,680] DEBUG - headers http-outgoing-1 >> Connection: Keep-Alive

You can see that in this request, which is going to the backend from the gateway, the user agent is the actual agent that invoked the api.

You can download the WSO2 API Manager and explore it’s cool features from this link.

Happy coding!

Thanks…

--

--