Pattern ignorecase = true, and ignorecase = false in extracting query param, what is the desired response

Not applicable

@Varun Singh

I am using extract variable policy. I want to extract one query param which can be passed in any case ( case insensitive, and any combinations of upper case and lower case should work. What is the approach that i should follow to accept query param with case insensitive comparison.

I tried with pattern ignore case = true.

The request below :-

But it is accepting the request only when i am giving it in the way i have named the query param and the dynamic variable as shown below.

Queryparam name = " validitySec"

<Pattern ignorecase = true >{validitySec)<\Pattern>

What should I do so that it accepts ValiditySec, VALIDITYSEC, validitysec and such combinations.

2 4 3,611
4 REPLIES 4

Yes -

In order to accept case insensitive query params, you will need to use JavaScript or another alternative to the ExtractVariables policy. The ignoreCase attribute you can use in the Pattern element applies to the pattern itself, not to the name of the query parameter.

Here's what I mean: when you use ExtractVariables on a query param, you are extracting something out of the query parameter itself. You already have the value of the query parameter in a variable. It is available in request.queryparam.QueryParamName , where you can replace QueryParamName with the name of your parameter.

Therefore if the inbound request is GET /foo/bar?baz=abc2872 then the context variable request.queryparam.baz contains the value "abc2872".

ExtractVariables allows you to extract some part of a value of a query param into another variable, according to a pattern or template that you provide. The ignoreCase attribute tells Edge to ignore the case in the provided value. An example. Suppose you use this code:

<ExtractVariables name="ExtractQuery-1">
    <QueryParam name="baz">
        <Pattern ignorecase="true">ABC{code}</Pattern>
    </QueryParam>
    <VariablePrefix>extracted</VariablePrefix>
</ExtractVariables>

...then with the same request as above, after the ExtractVariables, the context variable extracted.code will contain the value 2872. You've extracted a part of the complete value of the original query parameter.

To grab the value of a queryparam with a case-insensitive name, you can use a JavaScript callout that relies on the URI.js third-party URI-parsing library.

The JS Code would look like this:

// this code relies on https://medialize.github.io/URI.js
//
// that module must be included in the policy via
//   <IncludeURL>jsc://URI.js</IncludeURL>
function caseInsensitiveRetrieve(hash, key) {
  key = key.toLowerCase();
  var item = Object.keys(hash).find(function(element) {
        return (key == element.toLowerCase());
      });
  return (item)?hash[item]:null; 
}
var uri = new URI(context.getVariable('proxy.url'));
var vsec = caseInsensitiveRetrieve(uri.search(true), 'validitySec');
if (vsec) {
  context.setVariable('extracted.validitySec', vsec);
}

And the JS policy configuration looks like this:

<Javascript name="JavaScript-1">
    <IncludeURL>jsc://URI.js</IncludeURL>
    <ResourceURL>jsc://extractQuery.js</ResourceURL>
</Javascript>

in condition you can use 

EqualsCaseInsensitive

yes, that operator exists for use in Conditions.  but that solves a different problem than is being discussed here.

Since this post is old, I would like to see if case insensitive query params can be extracted/captured in Assign Message or Extract Variables policy? Or is JS policy the only option?

For reference the request can be either 

GET /foo/bar?employeeid 

GET /foo/bar?employeeId

GET /foo/bar?EmployeeId