Skip to main content

HTTP Macros

CEL provides a set of predefined macros that can also be used in policy expressions. For convenience, the following custom macros are also supported:

NameReturn TypeDescription
hasReqHeader(string)boolReturns true or false if the provided header key is present on the request. Header keys must be written in canonical format.
getReqHeader(string)listReturns a list of header values for the provided key on the request. Header keys must be written in canonical format.
hasQueryParam(string)boolReturns true or false if the specified query parameter key is part of the request URL.
getQueryParam(string)listReturns a list of the query parameter values from the request URL for the specified key.
hasReqCookie(string)boolReturns true or false if a cookie exists on the request with the specified name.
getReqCookie(string)boolReturns the cookie struct for the specified cookie name, if it exists on the request.
hasResHeader(string)boolReturns true or false if the provided header key is present on the response. Header keys must be written in canonical format.
getResHeader(string)listReturns a list of header values for the provided key on the response. Header keys must be written in canonical format.
hasResCookie(string)boolReturns true or false if a cookie exists on the response with the specified name.
getResCookie(string)boolReturns the cookie struct for the specified cookie name, if it exists on the response.
inCidrRange(ip string, cidr string)boolReturns true or false if the provided IP address falls within the provided CIDR range. Returns false if the provided CIDR range is invalid.
inCidrRanges(ip string, cidrs list)boolReturns true or false if the provided IP address falls within any of the provided CIDR ranges. Ignores any provided CIDR ranges that are invalid.

hasReqHeader(string)

Returns true or false if the provided header key is present on the request. Header keys must be written in canonical format.

# snippet
---
expressions:
- "hasReqHeader('X-Version-Id')"

getReqHeader(string)

Returns a list of header values for the provided key on the request. Header keys must be written in canonical format.

# snippet
---
expressions:
- "getReqHeader('User-Agent').exists(v, v.matches('(?i)google-images'))"

hasQueryParam(string)

Returns true or false if the specified query parameter key is part of the request URL.

# snippet
---
expressions:
- "hasQueryParam('q')"

getQueryParam(string)

Returns a list of the query parameter values from the request URL for the specified key.

# snippet
---
expressions:
- "size(getQueryParam('q')) == 0"

hasReqCookie(string)

Returns true or false if a cookie exists on the request with the specified name.

# snippet
---
expressions:
- "hasReqCookie('session')"

getReqCookie(string)

Returns the cookie struct for the specified cookie name, if it exists on the request.

# snippet
---
expressions:
- "getReqCookie('session').Secure"

hasResHeader(string)

Returns true or false if the provided header key is present on the response. Header keys must be written in canonical format.

# snippet
---
expressions:
- "hasResHeader('Content-Type')"

getResHeader(string)

Returns a list of header values for the provided key on the response. Header keys must be written in canonical format.

# snippet
---
expressions:
- "size(getResHeader('Content-Type').filter(v, v.matches('application/json')))
> 0"

hasResCookie(string)

Returns true or false if a cookie exists on the response with the specified name.

# snippet
---
expressions:
- "hasResCookie('_device_id')"

getResCookie(string)

Returns the cookie struct for the specified cookie name, if it exists on the response.

# snippet
---
expressions:
- "getResCookie('_device_id').Value == 'mobile-phone-14'"

inCidrRange(ip string, cidr string)

Returns true or false if the provided IP address falls within the provided CIDR range. Returns false if the provided CIDR range is invalid.

# snippet
---
expressions:
- "inCidrRange(conn.client_ip, '66.249.66.1/24')"

inCidrRanges(ip string, cidrs list)

Returns true or false if the provided IP address falls within any of the provided CIDR ranges. Ignores any provided CIDR ranges that are invalid.

# snippet
---
expressions:
- "inCidrRanges(conn.client_ip, ['66.249.66.1/24', '2001:4860::/32'])"