How to install the Process Request Data Into Headers integration from Azion Marketplace
Process Request Data Into Header is a serverless integration available at Azion Marketplace.
The purpose of this function is to stop a request whenever a request body field is empty. Using regex, the user can validate not only whether the field exists but also patterns. Additionally, they have the option to use any behavior they choose rather than a predetermined Deny Request
.
Getting the integration
To install the integration, follow these steps:
- Access Azion Console > Marketplace.
- On the Marketplace homepage, select the integration’s card.
- Once the integration’s page opens, click the Install button.
You’ll see a message indicating that your integration was successfully installed.
- Access Real-Time Manager (RTM) > Marketplace.
- On the Marketplace homepage, select the integration’s card.
- Once the integration’s page opens, click the Get It Now button, at the bottom-right corner of the page.
You’ll see a message indicating that your integration was successfully installed.
Configuring the integration
Setting up an edge firewall
To instantiate the Process Request Data Into Header integration, follow the steps:
- On the Products menu, select Edge Firewall in the SECURE section.
- Click the + Edge Firewall button.
- Give an easy to remember name to your edge firewall.
- Select the domains you want to protect with the function.
- Turn the Edge Functions switch on.
- Click the Save button.
Done. Now you have instantiated the rule for your function.
- On the Products menu, select Edge Firewall in the SECURE section.
- Click the Add Rule Set button.
- Give an easy to remember name to your edge firewall.
- Select the domains you want to protect with the function.
- Turn the Edge Functions switch on.
- Click the Save button.
Done. Now you have instantiated the rule for your function.
Setting up the integration
To instantiate the Process Request Data Into Header integration, while still on the Edge Firewall page:
- Select the Functions Instances tab and follow these steps:
- Click the + Function Instance button.
- Give an easy to remember name to your instance.
- On the dropdown menu, select the Process Request Data Into Header function.
- This function doesn’t address any argument on the Arguments tab, but you can test it using the
curl
command.
- This function doesn’t address any argument on the Arguments tab, but you can test it using the
- Select the Functions tab and follow these steps:
- Click the Add Function button.
- Give an easy to remember name to your instance.
- On the dropdown menu, select the Process Request Data Into Header function.
This action will load the function, showing a form with the function’s source code and, just above it, two tabs: Code and Args. By clicking the Code tab, you’ll be able to navigate through the source code but won’t be able to change it. Also, this function doesn’t address any argument on the Args tab, but you can test it using the curl
command.
Curl command examples
Curl Command | Request headers added by the function |
---|---|
curl https://mydomain/function | X-Body-Error": "CT001 |
curl -H "Content-Type: application /x-www-form-urlencoded" --request POST --data 'param1=v1¶m2=v2¶m3=v3' https://mydomain/function | X-Body-Param1": "v1" X-Body-Param2": "v2" X-Body-Param3": "v3" |
curl -H "Content-Type: application /json" --request POST --data '{"my_data": {"abc": {"def": {"g": "xyz","h": false,"e": null}}, "number": 1}}' https://mydomain/function | X-Body-My-Data-Abc-Def-G": "xyz" X-Body-My-Data-Abc-Def-H": "false" X-Body-My-Data-Number": "1" |
curl -H "Content-Type: text /plain" --request POST --data 'plain=text' https://mydomain /function | X-Body-Error": "CT002" |
curl -H "Content-Type: application /json" --request POST --data '{"my_data": {"abc": {"def": {"g": "xyz","h": false,"e": null}}, "number": 1}' https://mydomain/function | X-Body-Error": "FD001" |
Possible errors
This integration can trigger errors. In this case, the errors will be appended to a new header called X-Body-Error
.
Error Code | Description |
---|---|
CT001 | The header Content-Type is missing or it’s null |
CT002 | The header Content-Type has a value, but it isn’t supported by the function |
FD001 | The request body isn’t correctly formatted and couldn’t be decoded |
Setting up the Edge Firewall Rules Engine
To finish, you have to set up the Rules Engine to configure the behavior and the criteria to run the integration.
Still in the Edge Firewall page:
- Select the Rules Engine tab.
- Click the + Rule Engine button.
- Name your rule something easy to remember.
- Select a criteria to run and catch the domain you want to run the integration on.
- Below, select a behavior to the criteria. In this case, it’ll be Run Function. Then, select the adequate Process Request Data Into Header function, according to the name you gave it in the instantiate step.
- Click the Save button.
Done. Now the Process Request Data Into Header integration is running for every request made to the domain you indicated.
- Select the Rules Engine tab.
- Click the New Rule button.
- Name your rule something easy to remember.
- Select a criteria to run and catch the domain you want to run the integration on.
- Below, select a behavior to the criteria. In this case, it’ll be Run Function. Then, select the adequate Process Request Data Into Header function, according to the name you gave it in the instantiate step.
- Click the Save button.
Done. Now the Process Request Data Into Header integration is running for every request made to the domain you indicated.