Chandra Mohan
Chandra Mohan

Reputation: 771

Azure APIM inbound policy ignore case for the property name

I have inbound policy as below

<choose>
 <when condition="@((context.Request.Body != null) && context.Request.Body.As<JObject> 
   (preserveContent: true)["ChannelID"] != null)">
   <set-header name="channelId" exists-action="override">
    <value>"@(context.Request.Body.As&amp;amp;amp;lt;JObject&amp;amp;amp;gt;(preserveContent: true) 
    ["ChannelID"])"</value>
   </set-header>
 </when>
</choose>

But the inboundpolicy treating the ChannelID as case sensitive.In the request body if we pass as channelId then ChannelID property is not getting recognized.

How can we make the property name as case insensitive in the inbound policy?

Upvotes: 0

Views: 2315

Answers (2)

Chandra Mohan
Chandra Mohan

Reputation: 771

I found the solution.Since it is a JObject, we can add case ignore as follow.

<choose>
<when condition="@((context.Request.Body != null) && context.Request.Body.As<JObject>(preserveContent: true).GetValue("channelId", StringComparison.OrdinalIgnoreCase)?.Value<string>() != null)">
    <set-header name="channelId" exists-action="override">
        <value>@(context.Request.Body.As<JObject>(preserveContent: true).GetValue("channelId", StringComparison.OrdinalIgnoreCase)?.Value<string>())</value>
    </set-header>
</when>

Upvotes: 1

Joey Cai
Joey Cai

Reputation: 20097

You can use the check-header policy to enforce that a request has a specified HTTP header.

<check-header name="header name" failed-check-httpcode="code" failed-check-error-message="message" ignore-case="true">
    <value>Value1</value>
    <value>Value2</value>
</check-header>

ignore-case : Can be set to True or False. If set to True case is ignored when the header value is compared against the set of acceptable values.

For more details, you could refer to this article.

Upvotes: 0

Related Questions