Custom Rules


Custom rules are used to give better control over HTTP Proxy message handling, and as an interface to the HTTP Proxy JavaScript API.

When Use Custom Rules is selected, every incoming message is checked against the rules. Only if none of the rules match the message, is the default operating mode used (see Setting Operating Modes).

Rules are tested serially, from top to bottom, until a matching rule is found. A rule is considered to match only if its condition matches, and it has an action. Once a matching rule is found no further rules are checked.

Creating Custom Rules

To create a custom rule:

  1. From the Edit menu, choose Custom Rule. The Custom Rules window opens.
  2. The first three columns in the Custom Rules table define the Rule Condition: Match Object, Direction, Header Name.
  3. The Regular Expression column allows you to add a regular expression to the rule.
  4. The final column, Action, specifies what HTTP Proxy will do when a rule matches the request/response.
  5. Click Add to add a rule to the ruleset.
  6. Click Delete to delete a selected rule in the table from the ruleset.
  7. Click OK to save the ruleset and return to the Main window.

Match Object

This field determines which part of the message HTTP Proxy should try to match.

Match Object Values
Value
Description
Action
Match the request action. The action is the path and any query parameters. If the message is a response, its associated request will be matched.
Host:Port
Match a string of the form host:port (this is always the web-server address). Host may be an IP address, if Reverse DNS is not enabled, or if it failed.
Method
Match the request method. If the message is a response its associated request is matched.
Header
Match the value of a specific header, given in the Header Name field.
Res. Code
Match the string consisting of the integer response code and the response explanation. If the message is a request it will not match.
Body
Match the message body. This requires the body to be read into memory completely, so it may slow HTTP Proxy down considerably (especially if used on responses).

Direction

This field determines whether the rule can match requests, responses, or both (select *).

Header Name

This field is only used if the Match Object is Header; otherwise it is ignored.

It specifies the name of the header whose value will be matched. The drop down lists supplies commonly used headers, but you may use any name.

Regular Expression

Enter a regular expression. HTTP Proxy will match it against the object determined by the previous fields. Almost any valid PERL5-compatible regular expression may be used (the actual syntax is from java.util.regex.Pattern).

Action

There are four basic actions.
Basic Actions
Action
Description
********
No action (the rule is commented out)
HOLD
Hold the message (as if Manual Mode was selected)
PASS
Pass the message on (as if Automatic Mode was selected)
DELETE
Delete the message and close both the connection to the browser and the connection to the server (as if Delete Request was pressed)

In addition, any functions defined using the HTTP Proxy JavaScript API will also appear as possible actions. When the condition matches for a rule with a javascript action, the selected function will be called, and its return value will be used as the actual action.

Saving and Loading Rules

The current ruleset will be automatically stored in a file named defaultRules.rules in the Template Directory when HTTP Proxy exits. If the file exists, it will be automatically loaded when HTTP Proxy starts.

You may also store rules on demand and load them as needed, using the button in the Custom Rules window.