Modify Client Response
  • 17 Jul 2024
  • 5 Minutes to read
  • PDF

Modify Client Response

  • PDF

Article summary

Overview

This feature lets you modify the client response by manipulating the response received from the origin. You can modify the status code, 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 client response. 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 Client Response rule supports the following actions:

ActionDescription
Status Code OverrideSets the HTTP status code in the Client Response, overriding the status code received from the origin.
Add HeaderAdds the header and header value to the response, 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 response, this action adds the header and specified value to the response.
Delete HeaderDeletes all instances of the named header from the response.

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 Client Response rule:

  1. Navigate to the Select Rule dialog.

  2. In the Select Rule dialog, choose Modify Client Response.
    modifyClientResponseMain80.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 client response.
    The Modify Client Response rule supports configuring multiple actions to be applied to the Client Response. Configure them one at a time.
    a. From the Action menu, select an action type.
    b. Set the action attributes.
    c. Choose Add Action.
    d. Repeat, to define additional actions.

  5. Choose Add Rule.

    Note: The CDN applies the actions in the order in which they appear in the component. So it is important to organize them in a logical sequence. See Rule Order.

Action Attributes

Each Action type has its own attributes to define.

  • Status Code Override

    • Status Code: The status code to be returned to the client. For example, '200.'

  • Add Header

    • Header Name - The name of the header to be added to the response.
    • Header Value - Select Value and enter a fixed value, or select Expression and enter a MEL expression that will determine the header value.

  • Replace Header

    • Header Name - The name of the header that, if present, will have its value replaced; otherwise, it will be added to the response.
    • Header Value - Select Value and enter a fixed value, or select Expression and enter a MEL expression that will determine the header value.


  • Delete Header
    • Header Name - The name of the header to be deleted from the response.

Examples

Add Header

This is an example of an Add Header action that instructs the CDN to add the "x-cdn" header to every client response, with the header value, "qwilt".

ModifyClientResponseAddHeader.png

Replace Header

This an example of a Replace Header action. Any instance of the "x-cdn" header in the client response is assigned the value, "qwilt." If no instance of the header is found, the header is added to the response and assigned the value, "qwilt."
ModifyClientResponseReplaceHeader.png

Status Code Override with Match Condition

This is an example of a Status Code Override action with a match condition. It tells the CDN that if a 5xx response code is present, replace it with a 503 response code.

ModifyClientResponseStatusCodeOverrideConditionalMatch75.png

SVTA Component: MI.ProcessingStages

When you save the site configuration, the client-response component is added to the JSON configuration within the MI.ProcessingStages component.

Examples

Add Header

This is an example of an Add Header action that instructs the CDN to add the "served-by" header to every client response, with the header value, "qwilt."

{
	"generic-metadata-type": "MI.ProcessingStages",
	"generic-metadata-value": {
		"client-response": [
			{
				"stage-metadata": [
					{
						"response-transform": {
							"headers": {
								"add": [
									{
										"value": "qwilt",
										"name": "served-by",
										"value-is-expression": false
									}
								]
							}
					  }
					}
				]
			}
		]
	}
}



The "value-is-expression":false attribute indicates a static header value. The header value, "qwilt," is specified in the "value" field.

Add Header with Value as Expression

The following illustrates the format 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": {
		"client-response": [
			{
				"stage-metadata": [
					{
						"request-transform": {
							"headers": {
								"add": [
									{
										"value": "<value construction expression>",
										"name": "x-cdn",
										"value-is-expression": true
									}
								]
							}
						}
					}
			}
		]
	}
}

Replace Header Value

This an example of a Replace Header action. Any instance of the "x-cdn" header in the client response is assigned the value, "qwilt." If no instance of the header is found, the header is added to the response 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 "server" header from the client response.

{
	"generic-metadata-type": "MI.ProcessingStages",
	"generic-metadata-value": {
		"client-response": [
			{
				"stage-metadata": [
					{
						"response-transform": {
							"headers": {
								"delete": [
									"server"
								]
							}
					  }
					}
				]
			}
		]
	}
}

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 client response only if the conditions set by the match expression are met.

{
	"generic-metadata-type": "MI.ProcessingStages",
	"generic-metadata-value": {
		"client-response": [
			{
				"stage-metadata": [
					{
						"response-transform": {
							"headers": {
								"add": [
									{
										"value": "qwilt",
										"name": "served-by",
										"value-is-expression": false
									}
								]
							}
						}
					}
				],
				"match": {
					"expression": "req.uri.query.foo == 'bar'"
				}
			}
		]
	}
}

Status Code Override

This is an example of a Status Code Override action that instructs the CDN to replace the HTTP status code received from the origin with status code '200 ' before sending the client response.

{
	"generic-metadata-type": "MI.ProcessingStages",
	"generic-metadata-value": {
		"client-response": [
			{
				"stage-metadata": [
					{
						"response-transform": {
							"response-status": "200"
						}
					}
				]
			}
		]
	}
}

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.