'APIM liquid How to check that the coming request include specific header?

I am trying to write an inbound policy inside one operation in an API in Azure API Management. In this policy I want to check if the incoming request has a specific header or not.

I am quite a beginner in liquid and in writing policies. But I have tried this solution but it doesn't work:

<set-variable name="testVar" value="@(context.Request.Headers["Xheader"]?[0])" />

I want to set the variable to have the header value if it exist otherwise to have null, empty string or any similar thing that indicate that the header doesn't exist



Solution 1:[1]

I found this Solution:

<set-variable name="nourVar" value="@(context.Request.Headers.GetValueOrDefault("xx","").Contains("encoded-type-01") )" />

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ibda