Header Injection Policy

Policy name

Header Injection

Summary

Adds headers to a request or a response

Category

Transformation

First Mule version available

v4.1.0

Returned Status Codes

500 - The configuration includes an expression that was not evaluated.

The Header Injection policy adds HTTP headers to the request or response of a message. When you configure this policy for your API, you must specify an inbound and outbound map of the headers that you want to add in the message processing in the form of a key-value pair:

header inject remove diagram

You can optionally include DataWeave expressions for Mule 4.0 and Mule runtime engine (Mule) expressions for Mule 3.0 and in the value of the header:

“#[attributes.requestPath]”

In this example, all the headers matching the configured expression are injected to the message.

How This Policy Works

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:

inbound header map
Figure 1. Inbound Header

+ .Outbound Header image::outbound-header-map.png[]

To overwrite an existing message header, remove the existing header before you add your header.

Configuring Policy Parameters

To create your Header Injection policy, configure the following parameters:

Parameter Description

Inbound Header Map

List of header names or regular expressions (comma-separated) to be injected at the beginning of the message processing, for example, host, content.*

Outbound Header Map

List of header names or regular expressions (comma-separated) to be injected at the end of the message processing, for example, content-type

Method & Resource conditions

The option to add configurations to only a select few or all methods and resources of the API

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

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub