Skip to main content

List of rule and action type that can be set for Actions

In the KurocoEdge rule addition screen, you can set actions for requests and responses, which are referred to as operations. You can set rules and processes for actions and configure how they behave when accessed.

Here, we will explain the rules and processes that can be set for each action for both requests and responses.

Action creation screen

On the rule list page, you can create a new rule by clicking [Add].

Image from Gyazo

Set each action on the request and response tabs.

Image from Gyazo

Rule structure explanation

Each rule may define any number of actions for either Request or Response. The actions are processed in order of priority from highest to lowest.

Each action has the following configuration options :

NameExplanation
Directive FlagOptional configuration that affects general behavior of the current action
Condition/VariableThe conditions that all need to be verified in order for the action settings to be processed. Most conditions also allow to capture data and store it as variables for further use
SettingsThe list of settings to apply to the given request/response. They are appplied in order (highest first)

Request and Response tabs have each access to their own set of meaningful conditions & settings for their context.

tip

Capturing named variables in regex is done like this :(?P<my_variable>.*)
And using them is done like this :{$my_variable}

Request

On Request tab, the rules apply to the requests issued by the browser before they reach the origin backend.

Conditions that can be set for requests

FieldSettingsDescription
MethodRequest MethodOK if the request's method matches the specified one :
  • GET
  • POST
  • PUT
  • PATCH
  • DELETE
  • OPTIONS
  • HEAD
IP AddressIP address patternApply a (possibly capturing) regex to the IP address of the user
GeolocationType, Value patternSelect the type of position information from the following and set conditions with regular expressions:
  • AreaCode
  • AsName
  • AsNumber
  • City
  • Continent
  • CountryCode
  • CountryCode3
  • CountryName
  • Latitude
  • Longitude
  • PostalCode
  • Region
  • UtcOffset
PathPath patternApply a (possibly capturing) regex to the request path
Query StringName, Value patternApply a (possibly capturing) regex to the value of the given query parameter by name
HeaderHeader field, Value patternApply a (possibly capturing) regex to the value of the given header by name
CookieKey, Value patternApply a (possibly capturing) regex to the value of the given cookie by name. Cookies are parsed from the cookie header before any rule applies (including those potentially changing Cookie header)
BodyBody patternBuffer the entire request body in the memory and apply a (possibly capturing) regex to it.
Beware of capturing large request bodies. When buffering bodies, memory consumption for each request is increased. And Edge services is pay per use, so using more memory costs more money to the client.
There is also a risk to go beyond the allowed limit and have request failure, in addition to the cost
Body prefixByteSize, Body patternBuffer a given amount of first bytes of the request body in memory, and apply a (possibly capturing) regex to these only. It is a more performant option than Body in case of large bodies, when the required data is located early
Static VariablesVariable name, ValueDefine a string variable directly within the rule. The value may use other previously captured variables
API VariablesAPI endpoint, Cache, First byte timeout, Method, Headers, Expected variable(s), Request cookies to be forwarded to the APIExecute an external API request, and build variables from the response. JSON object response body is expected. All API requests defined within the same rule
Match ValueExpression, Value patternMatches left side expression with the right one. Captured variables may be used on either side

Processes that can be set for requests

FieldSettingsDescription
HeaderOperation, header field, Value, URL encode"Add or Replace" inserts new header or overwrites if one already exists, where "Match & Replace" allows to match & replace only the captured parts of the value using a regex
CookieOperation, Name, Value"Add or Replace" inserts new cookie or overwrites if one already exists, where "Match & Replace" allows to match & replace only the captured parts of the value using a regex
FilePath(in Filemanager)File managerMaps this request to return whatever is at the given path in the Filemanager of the connected Kuroco admin panel. In set, this request will not be forwarded to the default origin backend
Backend URLDomain, PathSpecify a destination where this request will be forwarded. This allows to route requests from the same frontend to multiple backends at once
Synthetic ResponseHTTP Status, Content Type, Body HTML, HeadersRespond with a handcrafted synthetic response. Optionnally additional response headers may be specified. Captured variables may be used in the body or header values
Redirect URLHTTP Status, URLSelect the redirect method and enter the URL of the redirect destination.
The following redirect methods are available:
  • 301 Premanent Redirect
  • 302 Temporary Redirect
. This effectively creates a Synthetic Response with the specified URL in the Location header and with the specified HTTP Status

Response

On Response tab, the rules apply to the response issued by the origin server before it is sent back to the user

Conditions that can be set for response

FieldSettingsDescription
HTTP statusHTTP response status code patternApply a (possibly capturing) regex to the HTTP status code (200, 404, etc)
HeaderName, Value patternApply a (possibly capturing) regex to the value of the given header by name
CookieOperation, Name, Value"Add or Replace" inserts new cookie or overwrites if one already exists, where "Match & Replace" allows to match & replace only the captured parts of the value using a regex
BodyPrefixBytesize, Body patternBuffer a given amount of first bytes of the response body in memory, and apply a (possibly capturing) regex to these only. It is a more performant option than Body in case of large bodies, when the required data is located early
Static VariablesName, ValueDefine a string variable directly within the rule. The value may use other previously captured variables
API VariablesURLExecute an external API request, and build variables from the response. JSON object response body is expected. All API requests defined within the same rule. Use Preload option to dispatch the request early to execute it in parallel with the origin request if the origin response data is not needed for this API call
Match valiable valueValue, MatchMatches left side expression with the right one. Captured variables may be used on either side

Processes that can be set for response

FieldSettingsDescription
HTTP statusHTTP response status code patternSet the HTTP status code (such as 200, 404, etc.).
HeaderOperation, Name, Value"Add or Replace" inserts new header or overwrites if one already exists, where "Match & Replace" allows to match & replace only the captured parts of the value using a regex
CookieOperation, Name, Value"Add or Replace" inserts new cookie or overwrites if one already exists, where "Match & Replace" allows to match & replace only the captured parts of the value using a regex
Browser CacheTTL (max-age)Set the number of seconds for this request be cached for in the browser
Edge CacheTTL (max-age)Set the number of seconds for this request be cached for on the Edge
HTML CrawlCSS Selector, JSON Path, JSON Value listUse this feature to capture parts of of the HTML body. The captured data can be used in a ShadowApi formatter to be injected either at the end of the body in a script tag as a JS variable, or the whole response can be changed to output the captured JSON variables only (instead of HTML)
Text Replacefrom, toReplace the text in the response with the specified text before and after replacement.
HTML EditorClick "Edit" and open the setting modalRefer to the HTML Edit section for detailed instructions.
Synthetic ResponseHTTP Status, Content Type, Body HTML, HeadersRespond with a handcrafted synthetic response. Optionnally additional response headers may be specified. Captured variables may be used in the body or header values
Redirect URLHTTP Status, URLSelect the redirect method and enter the URL of the redirect destination.
The following redirect methods are available:
  • 301 Premanent Redirect
  • 302 Temporary Redirect

HTML Editor

In HTML editor, you can make modifications to the HTML that KurocoEdge retrieves from the backend host before responding to the browser.

Image from Gyazo

FieldDescription
GeneralSpecify the range of HTML to be edited using CSS selectors.
Optionally, selecting "Hide" will set display: none; for the specified range.
Optionally, selecting "Delete" will remove the specified range.
Tag AttributesYou can add, remove, or replace tags for the elements specified by CSS selectors.
Tag ContentAdd text to the elements specified by CSS selectors. If there are child elements, the specified text will be added to each element.
HTML InjectionInsert additional HTML into the elements specified by CSS selectors. Choose the position to insert the HTML from the following options:
  • At the beginning of the child elements
  • At the end of the child elements
  • Immediately before the element
  • Immediately after the element

Support

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