Rewrite Rules

How to rewrite portions of requests

Answers: How to modify parts of a request?

Rewrite rules enable modification of any part of a request. Rules are applied if a request URL matches the provided regex pattern. If there are no rewrite rules or a request URL does not match any of the rule patterns, then there will be no modifications to the intercepted request.

Rule Configuration

Method

HTTP verb(s) the rule applies to such as GET, POST, DELETE, etc.

Pattern

Pattern to match with the request URL to apply the rule to. This supports regular expressions.

Parameters

Which components of the request to match on, such as header, body, and query param.

Name

Name of the component

e.g. for the header Authorization: Token , the name is Authorization

Value

Value of the component

e.g. for the header Authorization: Token , the value is Token

Modes Applied To

Which agent mode to apply the firewall rule to such as mock, record and/or replay

Example

For example, say you want to record requests to endpoints that require valid OAuth tokens. Let's say that endpoint is GET https://internal.company.com/v1/users . Then you can create a rewrite rule with the followin values:

  • Method - GET

  • Pattern - https://internal.company.com/v1/users

  • Parameter Type - Header

  • Parameter Name - Authorization

  • Value - REDACTED TOKEN

  • Modes Applied To - Record

When recording, this will configure the agent to rewrite the Authorization header's value with REDACTED TOKEN. Similarly, when replaying a request, we can also create a rule set this same header with a valid token. For advance use cases, see:

How to Create Lifecycle Hooks

Last updated