Skip to main content

Using Variables in KurocoEdge – Captured Variables

info

Estimated required time:7 min

Overview

KurocoEdge allows you to define 'captured' variables within a Rule's Action. Unlike 'static' or 'API' variables, which are explicitely defined in the 'Conditions / Variables' section of an Action, this special type of variable is created as a captured 'Field settings' value (the value of a 'Header', 'Body prefix', or 'Match variable value'), using the regular expression syntax (?P<name>…).

This is a convenient, and versatile way to create variables 'on-the-fly' in KurocoEdge. These captured variables can then be reused like other KurocoEdge variables within the Action's 'Execution' section, with the {$variable} syntax.

What You Will Learn

Where to Define a 'Captured' Variable

Within the 'Condition / Variable' section of an Action, a captured variable can be created in a 'Field setting', using the standard regular expression syntax (?P<name>…).

info

For more information on how regular expression(regex) works, refer to How to use regex 101.

note

The regular expression syntax (?P<...>) is called Named Capture Groups, used to assign the captured value a custom alphanumeric name, instead of default $1 etc. KurocoEdge made a choice to not store unnamed numbered capture groups, as multiple rules can capture multiple variables, making unnamed numbered system not viable

For example, if you are creating a Header condition/variable, you can 'capture' the current value of the header and assign it to a variable.

To demonstrate, if we visit the Network tab in the development console in our browser, we can see that the current value of our 'Server' header in our Response Headers is nginx:

Image from Gyazo

Back in the KurocoEdge admin panel, we can set a new condition/variable in an Action, to capture this value.

First, select 'Header' in 'Field settings', then enter in the name of the header in the 'Header field' - in our case 'server'. To capture the whole current existing value of the 'server' header, we can enter (using the regex syntax mentioned above) (?P<test_server_value>.*)

Image from Gyazo

note

Note that the .* syntax that follows arrow brackets (<>) in the example above indicates that the entire value is being captured. It is of course possible to adjust the regex according to your needs, to capture various parts of the value using different regex parameters.

Configure an Action's 'Execution' Settings

To use this captured variable, we can now create a new header in the 'Execution' section of our Action, and assign the variable as the header's value.

In our case we will name this header captured_server_value and using the standard {$variable} syntax (for KurocoEdge variables), we will enter in {$test_server_value} as the header's value.

Image from Gyazo

This will inject the value of the previously captured test_server_value variable.

Test if the Variable is Working

If we return to the Network tab in the development console in our browser, we can see our new header has been created, displaying the same value (nginx) as the old 'server' header.

Image from Gyazo

This confirms that the value in this variable was captured properly and is now working in our Action as intended.


Support

If you have any other questions, please contact us or check out Our Discord Community.