context variable to dump all the headers and values in request/response object ?

Martin Kallukalam 335 Reputation points
2024-09-03T21:38:26.84+00:00

Is there a builtin APIM context variable that will list all the request headers?
I find there is a built in context variable which will list the header and value if I know the name of the header. My requirement is to list all the headers and possibly their values in the request object and response object .

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
2,074 questions
{count} votes

Accepted answer
  1. JananiRamesh-MSFT 26,546 Reputation points
    2024-09-04T06:41:35.5466667+00:00

    @Martin Kallukalam Thanks for reaching out. Yes, the context.Request.Headers context.Response.Headers variable provides access to all the request/response headers.

    You can indeed iterate over the context.Request.Headers dictionary to list all the request headers and their values.

    <set-variable name="allHeaders" value="@(string.Join(", ", context.Request.Headers.Select(h => h.Key + ": " + h.Value.FirstOrDefault())))" />

    This policy sets a variable allHeaders that contains a string with all the headers and their values, separated by commas. The FirstOrDefault() method ensures that you get the actual value of each header.

    do let me know incase of further queries, I would be happy to assist you.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.