---
schema_version: "1"
id: bd26050b8ee42282f17d48ec3e0427fd1b145b278da19c1b666a3f84d0667bac
title: Header Injection Policy
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/gateway/1.12/policies-included-header-injection.md
canonical_url: https://docs.mulesoft.com/gateway/1.12/policies-included-header-injection
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 2f1152f931e398d038a599859aad0283bca9d45d325fa76039cf6f5dbb029dc2
description: MuleSoft Documentation Site
release: "1.12"
latest: false
---
---
product: Omni Gateway
version: 1.12
keywords: header injection, api gateway, flex gateway, gateway, policy
---

# Header Injection Policy

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

<table><colgroup><col> <col></colgroup><tbody><tr><td><p><strong>Policy name</strong></p></td><td><p>Header Injection</p></td></tr><tr><td><p><strong>Summary</strong></p></td><td><p>Adds headers to a request or response.</p></td></tr><tr><td><p><strong>Category</strong></p></td><td><p>Transformation</p></td></tr><tr><td><p><strong>First Flex Gateway version available</strong></p></td><td><p>v1.0.0</p></td></tr><tr><td><p><strong>Returned Status Codes</strong></p></td><td><p>500 - The configuration includes an expression that was not evaluated.</p></td></tr></tbody></table>

## Summary

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.

![A flow chart illustrating the process of setting header injection and removal policies for clients accessing an API through a proxy](/mulesoft/current/en-us/gateway/1.12/_images/header-inject-remove-diagram.png)

You can optionally include DataWeave expressions in the value or name of the header. For example,
all headers matching the following configured expression are injected to the message:

`“#[attributes.requestPath]”`

If the injected header already exists in the message attributes, the policy creates a new header
without overriding the value of the existing one.

> [!NOTE] Only certain headers are restricted to support multiple values, and they will be
> overwritten using configured values. These headers are: `access-control-allow-origin`,
> `content-type`, `content-length`, `transfer-encoding`.
>
> To overwrite any other existing message header, remove it before adding your header. See the
> [Header Removal](https://docs.mulesoft.com/gateway/1.12/policies-included-header-removal) policy.

## Configuring Policy Parameters

### Flex Gateway Local Mode

When you apply the policy via declarative configuration files, Refer to the following policy
definition and table of parameters:

\- policyRef: name: header-injection-flex config: inboundHeaders: <array> // OPTIONAL, default:
\[\] - key: <string> // REQUIRED value: <string> // REQUIRED outboundHeaders: <array> // OPTIONAL,
default: \[\] - key: <string> // REQUIRED value: <string> // REQUIRED

<table><colgroup><col> <col> <col> <col></colgroup><thead><tr><th>Parameter</th><th>Required or Optional</th><th>Default Value</th><th>Description</th></tr></thead><tbody><tr><td><div><div><p><code>inboundHeaders</code></p></div></div></td><td><div><div><p>Optional</p></div></div></td><td><div><div><p>Empty array</p></div></div></td><td><div><div><p>List of headers to be injected at the beginning of the message processing.</p></div></div></td></tr><tr><td><div><div><p><code>inboundHeaders.key</code></p></div></div></td><td><div><div><p>Required</p></div></div></td><td><div><div><p>N/A</p></div></div></td><td><div><div><p>A string or DataWeave expression for header name</p></div></div></td></tr><tr><td><div><div><p><code>inboundHeaders.value</code></p></div></div></td><td><div><div><p>Required</p></div></div></td><td><div><div><p>N/A</p></div></div></td><td><div><div><p>A string or DataWeave expression for header value</p></div></div></td></tr><tr><td><div><div><p><code>outboundHeaders</code></p></div></div></td><td><div><div><p>Optional</p></div></div></td><td><div><div><p>Empty array</p></div></div></td><td><div><div><p>List of header to be injected at the end of the message processing.</p></div></div></td></tr><tr><td><div><div><p><code>outboundHeaders.key</code></p></div></div></td><td><div><div><p>Required</p></div></div></td><td><div><div><p>N/A</p></div></div></td><td><div><div><p>A string or DataWeave expression for header name</p></div></div></td></tr><tr><td><div><div><p><code>outboundHeaders.value</code></p></div></div></td><td><div><div><p>Required</p></div></div></td><td><div><div><p>N/A</p></div></div></td><td><div><div><p>A string or DataWeave expression for header value</p></div></div></td></tr></tbody></table>

> [!NOTE] `inboundHeaders` and `outboundHeaders` can not both be empty.

To use single quotes directly in a String value (for example
`"default-src 'none'; frame-ancestors 'none';"`), either:

- Use a DataWeave expression:

  #\["default-src 'none'; frame-ancestors 'none';"\]

- Use character escaping:

  "default-src \\'none\\'; frame-ancestors \\'none\\';"

#### Resource Configuration Example

In the following example, all the headers matching the configured `#[attributes.requestPath]`
expression are injected into the message.

\- policyRef: name: header-injection-flex config: inboundHeaders: - key: "new-inbound-header" value:
"#\[attributes.requestPath\]" outboundHeaders: - key: "new-outbound-header" value:
"#\[attributes.requestPath\]"

### Managed Flex Gateway and Flex Gateway Connected Mode

When you apply the policy from the UI, the following parameters are displayed:

<table><colgroup><col> <col></colgroup><thead><tr><th><strong>Parameter</strong></th><th><strong>Description</strong></th></tr></thead><tbody><tr><td><div><div><p>Inbound Header Map</p></div></div></td><td><div><div><p>List of headers to be injected at the beginning of the message processing.</p></div></div></td></tr><tr><td><div><div><p>Inbound Header Key</p></div></div></td><td><div><div><p>String or Dataweave expression to be used as header name at the beginning of the message.</p></div></div></td></tr><tr><td><div><div><p>Inbound Header Value</p></div></div></td><td><div><div><p>String or Dataweave expression to be used as header value at the beginning of the message.</p></div></div></td></tr><tr><td><div><div><p>Outbound Header Map</p></div></div></td><td><div><div><p>List of headers to be injected at the end of the message processing.</p></div></div></td></tr><tr><td><div><div><p>Outbound Header Key</p></div></div></td><td><div><div><p>String or Dataweave expression to be used as header name at the end of the message processing.</p></div></div></td></tr><tr><td><div><div><p>Outbound Header Value</p></div></div></td><td><div><div><p>String or Dataweave expression to be used as header value at the end of the message processing.</p></div></div></td></tr><tr><td><div><div><p>Method &amp; Resource conditions</p></div></div></td><td><div><div><p>The option to add configurations to only a select few or all methods and resources of the API</p></div></div></td></tr></tbody></table>

> [!NOTE] Header keys should be compliance with
> [HTTP 1.1](https://www.w3.org/Protocols/rfc2616/rfc2616-sec2.html#sec2.2) standard.

To use single quotes directly in a String value (for example
`"default-src 'none'; frame-ancestors 'none';"`), either:

- Use a DataWeave expression:

  #\["default-src 'none'; frame-ancestors 'none';"\]

- Use character escaping:

  "default-src \\'none\\'; frame-ancestors \\'none\\';"
