Modify Origin Request
  • 17 Jul 2024
  • 6 Minutes to read
  • PDF

Modify Origin Request

  • PDF

Article summary

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:

ActionDescription
URI ManipulationModifies the URI received from the client before sending the request to the origin.
Add HeaderAdds the header and header value to the request, in addition to any same-name headers that may already be present.
Replace HeaderReplaces 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 HeaderDeletes 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:

  1. Navigate to the Select Rule dialog.

  2. In the Select Rule dialog, choose Modify Origin Request.
    modifyOriginRequestMain80.png

  3. 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

    MatchConditionExample.png

  4. 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.

  5. Choose Add Rule.

Note:

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

AttributeDescription
Modify PathToggle On this option to manipulate the URI path. Then build the Regex expression and Build Rule.
Modify QueryToggle 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 StringAdds 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.
RemoveFirstPathSegment.png



This example uses Modify Query to remove the timestamp from the origin request URL.
RemoveTimestamp.png



This example removes all the query parameters from the URI and prepends it with /video.

RemoveAllQueryParamsPlusPrepend.png

  1. A Query Action is configured to instruct the CDN to remove all the query parameters from the origin request URI.
  2. Generate MEL produces this: req.uri.path
  3. 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

AttributeDescription
Header NameThe name of the header to be added to the request.
Header ValueSelect 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".
modifyOriginRequestAddHeaderExampleModified80focused.png


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.

ModifyOriginRequestAddHeaderAsValue.png

Replace Header

AttributeDescription
Header NameThe name of the header that, if present, will have its value replaced; otherwise, it will be added to the request.
Header ValueSelect 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."
ReplaceHeader80.png

Delete Header

AttributeDescription
Header NameThe 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
}   

Was this article helpful?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.