User-Agent header is not getting passed to target endpoint

I'm adding a user-agent header in assign message policy in pre flow of proxy endpoint. It is being shown in trace but not getting passed to the target endpoint. I checked the curl it made, user agent header is not there.

I'm setting header like this :

<Header name="user-agent">{request.header.user-agent}</Header>

in the curl it is not getting added

0 8 1,344
8 REPLIES 8

It looks like you're trying to set the user-agent header with the user-agent header value on the inbound request. ie setting the value to whatever the value is? If that's what you are doing, the Header element will be a no-op: if the original request includes a user-agent header, then it will retain that value. If the original request does not include a user-agent header, then the user-agent header will remain unset.

What exactly are you trying to do?

@dane knezic the original request includes the user-agent header but it is not retaining in target endpoint call. Here i'm trying to explicitly set the header but it is not working. I can see the user-agent header in trace but not in curl it is making to target server. Attaching the screenshot herescreen-shot-2020-01-10-at-111404-am.png

even if I try to set it to any value, it is not setting

<Headername="user-agent">whatsoeverValue</Header>

Did you try retaining the User-Agent header using the TargetEndpoint properties?

<Property name="request.retain.headers">User-Agent,Referer,Accept-Language</Property>

or enable all header

<Property name="request.retain.headers.enabled">true</Property>

https://docs.apigee.com/api-platform/reference/endpoint-properties-reference

BTW yes even I am not able to see the User-agent header in the cURL cmd shown in trace but I was can see that the User-agent header is being passed to my target endpoint.

{request.header.user-agent} ---> this will work.
{request.header.User-Agent} ---> this is recommended.

@Siddharth Barahalikar yes I tried setting these properties. Still, it does not retain the headers.

request.header.user-agent is working but only problem is that it is not passing the header to target endpoint. Any other header is being set properly except user-agent/User-Agent. APIGEE is not passing it further.

Could you try testing with POST Method - https://httpbin.org/post target endpoint and check/post the response.

{
  "args": {}, 
  "data": "", 
  "files": {}, 
  "form": {}, 
  "headers": {
    "Accept": "*/*", 
    "Content-Length": "0", 
    "Content-Type": "application/x-www-form-urlencoded", 
    "Host": "httpbin.org", 
    "Name": "sid", 
    "User-Agent": "custom-value"
  }, 
  "json": null, 
  "origin": "50.16.249.180, 35.223.222.179, 50.16.249.180", 
  "url": "https://httpbin.org/post"
}

Works fine for this endpoint. It means there is some problem with my target endpoint?

It's hard to say. how are you determining that the header is not reaching the target? You'll need to troubleshoot it and diagnose it yourself.