Hi Team,
In postman response i am able to see below header varibles with value.
Connection - keep-alive Content-Length - 410
I am able to read "Connection" value in AssignMessage using below syntax
response.header.Connection
Same way when i try to read below fields, i am not getting the value, its coming as empty value. response.header.Content-Length
request.header.Connection
Please let me know if there is any other way to get it.
Thanks, Satheesh.K
Can anyone please help on this request?
@kumarsathe Here's the simple proxy with an assignmessage policy that demonstrates how to add the response headers. In the sample response, you will find 2 headers x-custom-connection and x-custom-content-length which are added to the original response:
curl -v http://api.demo.apigee.net:9009/v1/demo/get < HTTP/1.1 200 OK < Server: nginx < Date: Sat, 29 Aug 2015 15:05:53 GMT < Content-Type: application/json < Content-Length: 187 < Access-Control-Allow-Origin: * < Access-Control-Allow-Credentials: true < x-custom-connection: keep-alive < x-custom-content-length: 187 < Connection: keep-alive < { "args": {}, "headers": { "Accept": "*/*", "Host": "httpbin.org", "User-Agent": "curl/7.43.0" }, "origin": "54.157.224.128", "url": "http://httpbin.org/get" }
Proxy zip attached.
Hi @kumarsathe,
If you are getting Content-Length value as null /empty you can simply calculate it using the below Javascript:
var contentLength = context.getVariable("response.header.Content-Length");
if ( ! contentLength ) {
var responseContent = context.getVariable('response.content');
contentLength = responseContent.length;
context.setVariable("response.header.Content-Length", contentLength);
}
Usually it is added by gateway once your response is created so if this header is not set, you can get the value using the above script .
As per above suggestion i able to get lengeth.
I am trying to get request.header.Connection using below code in js. In request i am passing 'Connection' parameter. but the value in coming as empty.
var reqConnection = context.getVariable("request.header.Connection"); context.setVariable("reqConnection", reqConnection);
if i change the variable name to 'Connection1' then able to get value. Why i am not able to get the value when i use 'Connection' ?
I am trying to get request.header.Connection using below code in js. In request i am passing 'Connection' parameter. but the value in coming as empty.
var reqConnection = context.getVariable("request.header.Connection"); context.setVariable("reqConnection", reqConnection);
if i change the variable name to 'Connection1' then able to get value. Why i am not able to get the value when i use 'Connection' ?
@kumarsathe It would depend on where the policy is being attached in the flow. I would suggest you look at the proxy I attached and see if it works. Instead of the assign message I have in the proxy, you can have the js policy above and the same should continue to work.
In PreFlow
Now I am trying to get request.header.Connection using below code in js. In request i am passing 'Connection' parameter. but the value in coming as empty.
var reqConnection = context.getVariable("request.header.Connection"); context.setVariable("reqConnection", reqConnection);
if i change the variable name to 'Connection1' then able to get value. Why i am not able to get the value when i use 'Connection' ?
@kumarsathe unless I take a look at your proxy, it would be hard to say. Can you attach your proxy and a sample call that you are making.
User | Count |
---|---|
3 | |
2 | |
1 | |
1 | |
1 |