Skip to content

CheckHeaderConfig forces Values be defined, but should be optional #186

@drjonnicholson

Description

@drjonnicholson

Report

According to https://learn.microsoft.com/en-us/azure/api-management/check-header-policy the CheackHeader policy does not require values.

We use this policy to check the presence of a header, but not enforce a specific value. For example:

context.CheckHeader(new CheckHeaderConfig()
{
Name = "x-correlation-id",
FailCheckErrorMessage = "Bad request. Missing correlation id in headers",
FailCheckHttpCode = 400,
IgnoreCase = false,
Values = []
});

Expected Behavior

The Values param does not need to be specified, or an empty array be permitted - in either case the resultant XML <check-header /> element would not contain any <value /> elements

Actual Behavior

Values is required, so must be provided. When it is, but left as empty, then the following error is encountered on compilation:

error APIM2007: Required 'Values' parameter for 'check-header' policy is empty but needs at least one element

Due to the above error the resultant XML does not include the <check-header/> output

Steps to Reproduce the Problem

This should be a minimum viable example:

using Microsoft.Azure.ApiManagement.PolicyToolkit.Authoring;
using Microsoft.Azure.ApiManagement.PolicyToolkit.Authoring.Expressions;

namespace SomeNamespace
{
    [Document(Scope = DocumentScope.Api)]
    public class AllOperations : IDocument
    {
        public void Inbound(IInboundContext context)
        {
            context.Base();

            context.CheckHeader(new CheckHeaderConfig()
            {
                Name = "x-correlation-id",
                FailCheckErrorMessage = "Bad request. Missing correlation id in headers",
                FailCheckHttpCode = 400,
                IgnoreCase = false,
                Values = []
            });
        }
    }
}

Component

Compiler

Version

Main

Contact Details

No response

Additional Information

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions