- 17 Jul 2024
- 6 Minutes to read
- Print
- PDF
Modify Origin Request
- Updated on 17 Jul 2024
- 6 Minutes to read
- Print
- PDF
Overview
This feature lets you modify the request to the origin by manipulating the request received from the client. You can modify the URI value, add, modify, or remove headers. MEL expressions can be used for generating dynamic values for these fields, and to create match conditions.
This is a Processing Stages rule that is applied to the origin request. If you add this rule to a path configuration, it is important to understand the inheritance logic. Learn more about Processing Stages rules..
Action Types
The Modify Origin Request rule supports the following actions:
Action | Description |
---|---|
URI Manipulation | Modifies the URI received from the client before sending the request to the origin. |
Add Header | Adds the header and header value to the request, in addition to any same-name headers that may already be present. |
Replace Header | Replaces the header value for all instances of the header that are already present. If the header is not already in the request, this action adds the header and specified value to the request. |
Delete Header | Deletes all instances of the named header from the request. |
Configure the Rule
Here, we'll describe how to configure the rule with the Delivery Service Management UI.
API Users may choose to build the site configuration offline.
To configure a Modify Origin Request rule:
In the Select Rule dialog, choose Modify Origin Request.
By default, the Rule Scope is set to Match All.
If you want to create a match condition, under Rule Scope, select Conditional Match and then create the match condition in the field that appears.Tip: See the MEL Quick Reference
Define an action to be applied to the origin request.
The Modify Origin Request rule supports configuring multiple actions to be applied to the Origin Request. Configure them one at a time.
To define a header manipulation:
a. From the Action menu, select an action type.
b. Set the action attributes.
c. Choose Add Action.
d. Repeat, to define additional actions.Note: The CDN applies the header manipulations in the order in which they appear in the component. So, it is important to organize them in a logical sequence. See Rule Order.
To define a URI Manipulation:
a. From the Action menu, select URI Manipulation.
b. Set the action attributes
c. Choose Generate MEL.
d. Optionally, in the URI Manipulation MEL field, continue editing the MEL expression.Choose Add Rule.
Every time you click Generate MEL, a distinct MEL expression is created. You can scroll through them in the URI Manipulation MEL field. However, only a single expression can be added to the site configuration. If multiple MEL expressions were defined, make sure the one you want to add to your site configuration is displayed in the URI Manipulation MEL field when you select Add Rule.
Action Attributes
Each Action type has its own attributes to define.
URI Manipulation
Attribute | Description |
---|---|
Modify Path | Toggle On this option to manipulate the URI path. Then build the Regex expression and Build Rule. |
Modify Query | Toggle On this option to enable keeping or removing specified query parameters. Then select a Query Action, and if relevant, specify the Query Parms to keep or remove. |
Additional Query Param String | Adds an additional query parameter string to the URI. The string may contain multiple parameters and values as well as the # character followed by a statement. |
This example uses Modify Path to remove the first path segment.
This example uses Modify Query to remove the timestamp from the origin request URL.
This example removes all the query parameters from the URI and prepends it with /video.
- A Query Action is configured to instruct the CDN to remove all the query parameters from the origin request URI.
- Generate MEL produces this:
req.uri.path
- The generated MEL displayed in the URI Manipulation MEL field is manually edited to instruct the CDN to prepend the origin request URI with '/video':
'/video' . requ.uri.path
Add Header
Attribute | Description |
---|---|
Header Name | The name of the header to be added to the request. |
Header Value | Select Value and enter a fixed value, or select Expression and enter a MEL expression that will determine the header value. |
This is an example of an Add Header action that instructs the CDN to add the "x-cdn" header to every origin request, with the header value, "qwilt".
This example adds a header with a value as expression. It instructs the CDN to add the Host header to the origin request, setting its value to the host header from the client request.
Replace Header
Attribute | Description |
---|---|
Header Name | The name of the header that, if present, will have its value replaced; otherwise, it will be added to the request. |
Header Value | Select Value and enter a fixed value, or select Expression and enter a MEL expression that will determine the header value. |
This an example of a Replace Header action. Any instance of the "x-cdn" header in the origin request is assigned the value, "qwilt." If no instance of the header is found, the header is added to the request and assigned the value, "qwilt."
Delete Header
Attribute | Description |
---|---|
Header Name | The name of the header to be deleted from the request. |
SVTA Component: MI.ProcessingStages
When you save the site configuration, the origin-request component is added to the JSON configuration within the MI.ProcessingStages component.
Add Header
This is an example of an Add Header action that instructs the CDN to add the "x-cdn" header to every origin request, with the header value, "qwilt".
{
"generic-metadata-type": "MI.ProcessingStages",
"generic-metadata-value": {
"origin-request": [
{
"stage-metadata": [
{
"request-transform": {
"headers": {
"add": [
{
"value": "qwilt",
"name": "x-cdn",
"value-is-expression": false
}
]
}
}
}
]
}
]
}
}
The "value-is-expression":false attribute indicates a static header value. The header value, "qwilt," is specified by the "value" field.
Add Header with Value as Expression
This is an example of an Add Header action that uses a MEL expression to determine the header value. The "value-is-expression":true attribute indicates a dynamic header value determined by an expression. The MEL expression is displayed in the "value" field.
{
"generic-metadata-type": "MI.ProcessingStages",
"generic-metadata-value": {
"origin-request": [
{
"stage-metadata": [
{
"request-transform": {
"headers": {
"add": [
{
"value": "req.h.host",
"name": "Host",
"value-is-expression": true
}
]
}
}
}
}
]
}
}
Replace Header Value
This an example of a Replace Header action. Any instance of the "x-cdn" header in the origin request is assigned the value, "qwilt." If no instance of the header is found, the header is added to the request and assigned the value, "qwilt."
{
"generic-metadata-type": "MI.ProcessingStages",
"generic-metadata-value": {
"origin-request": [
{
"stage-metadata": [
{
"request-transform": {
"headers": {
"replace": [
{
"value": "qwilt",
"name": "x-cdn",
"value-is-expression": false
}
]
}
}
}
]
}
]
}
}
Delete Header
In this example, the Delete Header action is used to remove the "x-forwarded-for" header from the origin request:
{
"generic-metadata-type": "MI.ProcessingStages",
"generic-metadata-value": {
"origin-request": [
{
"stage-metadata": [
{
"request-transform": {
"headers": {
"delete": [
"x-forwarded-for"
]
}
}
}
]
}
]
}
}
Add Header with Match Expression
This is an example of an Add Header action with a match expression. This configuration instructs the CDN to add the header to the origin request only if the conditions set by the match expression are met.
{
"generic-metadata-type": "MI.ProcessingStages",
"generic-metadata-value": {
"origin-request": [
{
"stage-metadata": [
{
"request-transform": {
"headers": {
"add": [
{
"value": "qwilt",
"name": "x-cdn",
"value-is-expression": false
}
]
}
}
}
],
"match": {
"expression": "req.uri.query.foo == 'bar'"
}
}
]
}
}
URI Manipulation
This is the format of the origin-request component that configures a URI Manipulation.
{
"generic-metadata-type": "MI.ProcessingStages",
"generic-metadata-value": {
"origin-request": [
{
"stage-metadata": [
{
"request-transform": {
"uri": "<MEL Expression>",
"uri-is-expression": true
}
}
]
}
]
}
}
This configuration instructs the CDN to remove the first path segment:
"request-transform": {
"uri": "match_replace(req.uri.path, '^/[^/]+(/.*)$', '$1') . ((req.uri.query == '') ? '' : '?') . req.uri.query",
"uri-is-expression": true
}
This example instructs the CDN to remove the timestamp:
"request-transform": {
"uri": "match_replace(req.uri.path, '^/[^/]+(/.*)$', '$1') . ((req.uri.query == '') ? '' : '?') . req.uri.query",
"uri-is-expression": true
}
This example instructs the CDN to remove all the query parameters and prepend the URI with the string '/video.'
"request-transform": {
"uri": "'/video' . req.uri.path",
"uri-is-expression": true
}