Do IBM Worklight HTTP Adapters (in 6.1) send a User-Agent header by default when invoking a back-end service using WL.Server.invokeHttp
? What is it's value? Assuming the answer is no, can we add one?
Asked
Active
Viewed 665 times
0

Andrew Ferrier
- 16,664
- 13
- 47
- 76
-
Andrew, if my answer below helped you resolve your problem, please mark it as Answered. – Idan Adar Sep 06 '14 at 15:08
-
Idan, thanks, but what I was hoping for was the actual header value itself :) Once I get a chance to try this out, I'll add that as answer. – Andrew Ferrier Sep 08 '14 at 08:44
2 Answers
3
In the adapter you can get the user agent the client sent like this:
var clientRequest = WL.Server.getClientRequest();
var userAgent = clientRequest.getHeader("User-Agent");
If you then want to pass this header along to a backend service:
var input = {
method :'get',
path : 'your/path',
headers: {
"User-Agent" : userAgent,
}
};
var result=WL.Server.invokeHttp(input);

Matt Cobb
- 405
- 5
- 13
1
When you invoke an adapter procedure, you can inspect the network using a tool such as Wireshark. There you will see that a User-Agent header is sent. This header is automatically added by the underlying Apache HTTPClient.
That said, you can add your own headers. Per the user documentation for WL.Server.invokeHttp
:
Parameters:
options - The invokeHttp function accepts the following JSON block of parameters:
...
...
...
headers. Optional. Defines the headers for the HTTP request.
For example:
var input = {
method : 'get',
headers: {foo: 'bar'},
path : '/mypath'
};
return WL.Server.invokeHttp(input);
As for its value, it may not have any value for you. It is just part of the standard.
See here for more (or google for additional information): HTTP request header: UserAgent variable