Daniel Lopez
unread,Dec 24, 2021, 6:58:06 AM12/24/21Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to KrakenD Community, akof...@gmail.com, Albert Lombarte, KrakenD Community
The req_headers maps a header to an array of strings. In order to access a value from the header array, you need to define the index.
One final comment, double check your endpoint config in order to pass the "version" header.
Here you have a working example:
{
"endpoint": "/cel",
"headers_to_pass":["version"],
"backend": [ ... ],
"extra_config":{
"github.com/devopsfaith/krakend-cel":[{
"check_expr": "1 > int(req_headers['version'][0])"
}]
}
}
$ curl -iH'version: 2' localhost:8080/cel
HTTP/1.1 500 Internal Server Error
X-Krakend: Version 1.4.1
X-Krakend-Completed: false
Date: Fri, 24 Dec 2021 11:56:47 GMT
Content-Length: 0
$ curl -iH'version: 1' localhost:8080/cel
HTTP/1.1 500 Internal Server Error
X-Krakend: Version 1.4.1
X-Krakend-Completed: false
Date: Fri, 24 Dec 2021 11:56:50 GMT
Content-Length: 0
$ curl -iH'version: 0' localhost:8080/cel
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
X-Krakend: Version 1.4.1
X-Krakend-Completed: true
Date: Fri, 24 Dec 2021 11:56:54 GMT
Content-Length: 18
{"message":"pong"}
Cheers!