Using a HTTP header as a curator trigger

Background

This article shows how you can use a HTTP header as a curator trigger.

Details

Curator provides a number of built-in trigger types that can be used when defining a curator rule. Unfortunately there isn’t a trigger type that uses a http header.

The following method can be applied to create a rule that is triggered by the presence of a http header.

Process

  1. Create a pre process hook script that maps the HTTP header to a custom input parameter.

  2. Create a curator rule using the Search URL contains parameters trigger and set it to the custom input parameter you used in the hook script.

Example: Trigger a curator rule using a X-Example-Group HTTP header

For this example we want to use the value of the X-Example-Group HTTP header to trigger a curator rule.

  1. The following pre process hook script maps the X-Example-Group HTTP header to a custom input parameter named httpHeaderXExampleGroup:

    hook_pre_process.groovy
    // Access the set of HTTP request headers
    def requestAttributes = org.springframework.web.context.request.RequestContextHolder.getRequestAttributes()
    if (requestAttributes instanceof org.springframework.web.context.request.ServletRequestAttributes) {
        def request = ((org.springframework.web.context.request.ServletRequestAttributes) requestAttributes).getRequest()
        // Get the value of the 'X-Example-Group' response header
        def header = request.getHeader("X-Example-Group")
    	// If the header is set map this to a custom input parameter httpHeaderXExampleGroup
        if (header) {
            transaction.question.inputParameterMap["httpHeaderXExampleGroup"] = header
        }
    }
  2. Create a curator rule with the following trigger

    • Search URL contains parameters: httpHeaderXExampleGroup

    Set the match type to the appropriate match for the trigger, and set the value to the value you wish to match. These control how the value of the HTTP header is matched against your condition.

  3. Configure any additional trigger conditions as normal

  4. Configure the curator action(s) as normal.

Debugging

  • Check that the request header is being detected correctly by viewing the JSON endpoint and ensure that the question.inputParameterMap["httpHeaderXExampleGroup"] is set to the value of the X-Example-Group HTTP header. If the header is being included in the request and it doesn’t show in the data model then check the hook script to ensure all the values are correct (they are case sensitive) and also check the modernui logs for the collection in case there is a syntax error in the hook script.

See also

  • Funnelback documentation: curator