Source conditions allow you to specify criteria for matching network requests. These criteria define where the rules should be applied, such as specific URLs, hosts, or paths.
Let's explore the elements of source conditions from left to right:
Select Source to Match
Select whether the matching should be performed on the host or the full URL.
Operator
Choose from four operators to define how the matching should be performed:
-
Equals: Matches exactly the specified value.
-
Contains: Matches if the value includes the specified substring.
-
Regex: Enables pattern matching using regular expressions.
-
Wildcard: Allows flexible pattern matching using wildcard characters.
Source Matching Field
The value of this field varies based on the operator selected. For Equals, enter the exact string to match, such as the full URL if you select the URL in the source. For Contains, provide a substring for broad matching across all URLs containing this string. For Regex, enter a regex pattern to match. For Wildcard, use a wildcard pattern to specify the matching criteria.
Advanced Filters
Enhance your source conditions with additional filters. These can be accessed using the filters button next to the input field:
-
Page Domain Name: Limit targeting to requests originating from a specific domain. This is especially useful for distinguishing between network calls made from different websites, such as CDN calls shared across multiple domains.
-
Resource Type: Specify the type of resource to limit matching to particular requests. For instance, path-level matching can apply to both CSS and JavaScript files, but advanced filters allow narrowing it down to only CSS or JavaScript as needed.
-
Request Method: Filter based on the HTTP method (e.g., GET, POST, OPTIONS). For example, two requests can have the same path but behave differently based on the method used. An API call to a resource with the GET method retrieves the resource details, while a PATCH call updates the resource.
Test URL Condition
The test URL condition feature is only applicable when using regex or wildcard operators. A button labeled Test Regex or Test Wildcard appears when you select these options. This feature helps you validate whether the rule source URL condition you have set up works for the request URL you want it to work with, improving the rule creation and editing experience.
To test a URL condition:
Open a Rule Editor
Start by opening any rule editor in the interface where you can define and edit source URL conditions.
Enter the Source URL Condition
Input the source URL condition using either the Regex or Wildcard operator, depending on your requirements.
Test the URL Condition
Click on the Test Regex or Test Wildcard button (depending on the selected operator). This will open a test URL popup modal for validation.
This popup modal includes the following components:
-
Source Condition: Displays the source condition defined in the rule editor. It is editable, allowing adjustments as needed.
-
URL Field: Enter the complete URL you want the rule to be applied to.
-
Result: Displays whether the rule will apply to the entered URL.
Testing URL with Regex Condition
To test a URL with a regex pattern in the source URL condition, enter the complete URL in the URL field. The result will indicate whether the rule applies to the URL based on the regex pattern.
Examples:
Source Condition | Match with URL | Is Matched |
---|---|---|
|
| Yes |
|
| Yes |
|
| No |
Ensure the regex pattern in the source condition is valid and enclosed with slashes (/
).
Examples:
-
/^https://.*github.*/
✅ Valid regex -
/^https://.*github.*
❌ Invalid regex
Testing URL with Wildcard Condition
To test a URL with a wildcard pattern in the source URL condition, enter the complete URL in the URL field. The result will indicate whether the rule applies to the URL based on the wildcard pattern.
Examples:
Source Condition | Match with URL | Is Matched |
---|---|---|
|
| Yes |
|
| Yes |
|
| No |