Free MuleSoft CONNECT Keynote & Expo Pass Available!

Register now+
Nav

To Apply Header Injection and Removal Policies (Mule 4)

Supported runtimes: Mule Runtime 4.1.0 and later.

The Header Injection policy adds headers to the request/response of the message. The Header Removal policy removes all listed headers.

header inject remove diagram

To Apply the Header Injection Policy

To apply this policy to an API, specify an inbound/outbound map of the headers that you want to add in the message processing in the form of a key-value pair.

inbound header map
outbound header map

If the injected header already exists in the message attributes, the policy creates a new header, without overriding the value of the existing one. This action creates two headers with the same name.

Note: Comma separated values are not considered multiple values by the Mule HTTP Connector.

You can use DataWeave expressions to set a value. For example:

“#[attributes.requestPath]”

To overwrite the value of a header, remove it before injecting the header.

To Apply the Header Removal Policy

To apply this policy to an API, specify the header names as regular expressions, separated by commas.

For example:

remove inbound header
remove outbound header

The content-type and content-length headers of a request can be filtered by this policy, as shown in this example, as well as the host header.

In the response, only the content-type header is removed.