Creating Request and Response rules using Rules Engine for Edge Application
Rules Engine is an Edge Application capability that allows you to create no-code solutions that follow the business rules of your edge application.
With Azion Edge Application’s reverse-proxy architecture, the rules you create will be executed between either the Request phase, which contains data that a client sends to an origin server, or Response phase, which contains data from the origin that is sent to the client.
Learn more about Rules EngineCreating a request rule: Rewrite Request
Rules created in the Request phase will be executed before the request to the origin servers is completed. For instance, using the Rewrite Request behavior, you can create a rule to deliver content to a user from a specific URI without requiring that they use the exact path value from the origin in the request.
For the purposes of this guide, assume that your goal is to deliver the contents of the page /content/page.html
when a client makes a request for https://www.domain.com/page
. To create a rule that will rewrite this request:
- Access Azion Console > Edge Application.
- Select the edge application for which you want to create the rule.
- In the Main Settings tab, enable the Application Accelerator module.
- Click the Save button.
- Select the Rules Engine tab.
- Click the + Rule button.
- Give your rule a name and, if necessary, a description.
- Select Request Phase.
- In the Criteria section, configure your criteria as follows:
- If
${uri}
is equal to/page
- This criteria will identify the URL of the request by the URI trailing slash
/
.
- If
- In the Behaviors section, add the behavior you want your application to execute. In this case, Rewrite Request.
- The behavior selected takes an argument; to redirect the request to the page:
${uri}content/page.html
- This argument concatenates the
${uri}
variable, whose value is/
, to the page’s path.
- Click the Save button to save your rule.
- Access Real-Time Manager (RTM).
- On the upper-left corner of the page, go to Products menu > Edge Application.
- Select the edge application for which you want to create the rule.
- In the Main Settings tab, enable the Application Accelerator module.
- Click the Save button.
- Select the Rules Engine tab.
- Click the Add Rule button.
- On the dropdown menu, select Request Phase.
- Give your rule a name and, if necessary, a description.
- In the Criteria section, configure your criteria as follows:
- If
${uri}
is equal to/page
- This criteria will identify the URL of the request by the URI trailing slash
/
.
- If
- In the Behaviors section, add the behavior you want your application to execute. In this case, Rewrite Request.
- The behavior selected takes an argument; to redirect the request to the page:
${uri}content/page.html
- This argument concatenates the
${uri}
variable, whose value is/
, to the page’s path.
- Click the Save button to save your rule.
Now, when a request is made to the URL https://www.domain.com/page
, users should see the contents from the /content/page.html
page without having to specify the entire address in their browser.
Creating a response rule: Filter Response Header
Rules created in the Response phase will be executed before the response is delivered to the client. For example, you can create a rule that’ll remove an HTTP header from the response using the Filter Response Header behavior.
The Server
header stores information about the server that generated the response. By removing this header, clients won’t receive information about the infrastructure of your application, enhancing your security by reducing the information available to potential attackers.
To filter the Server
header from the response:
- Access Azion Console > Edge Application.
- Select the edge application for which you want to create the rule.
- In the Main Settings tab, enable the Application Accelerator module.
- Click the Save button.
- Select the Rules Engine tab.
- Click the + Rule button.
- Give your rule a name and, if necessary, a description.
- Select Response Phase.
- In the Criteria section, configure your criteria as follows:
- If
${uri}
starts with/
- This criteria will execute the rule for the entire application.
- In the Behaviors section, add the behaviors you want to be executed. In this case, Filter Response Header.
- The behavior selected takes an argument, which should be
Server
.
- This argument will remove every instance of the
Server
header from all responses.
- Click the Save button to save your rule.
- Access Real-Time Manager (RTM).
- On the upper-left corner of the page, go to Products menu > Edge Application.
- Select the edge application for which you want to create the rule.
- In the Main Settings tab, enable the Application Accelerator module.
- Click the Save button.
- Select the Rules Engine tab.
- Click the Add Rule button.
- On the dropdown menu, select Response Phase.
- Give your rule a name and, if necessary, a description.
- In the Criteria section, configure your criteria as follows:
- If
${uri}
starts with/
- This criteria will execute the rule for the entire application.
- If
- In the Behaviors section, add the behaviors you want to be executed. In this case, Filter Response Header.
- The behavior selected takes an argument, which should be
Server
.- This argument will remove every instance of the
Server
header from all responses.
- This argument will remove every instance of the
- Click the Save button to save your rule.
Now, when a request is made to your application, the Server
header will be removed from the response.