---
schema_version: "1"
id: 6ef2fce54e5842a58d941603e9b115411b6ebecc7fa26a1c9db287e3e01c0096
title: HTTP Policy Transform Extension
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/mule-gateway/policies-custom-http-transform.md
canonical_url: https://docs.mulesoft.com/mule-gateway/policies-custom-http-transform
source_site: docs.mulesoft.com
content_type: documentation
content_hash: b3f42d38fc51b56894a9a3eff8e419dbd8541867eb1cf47a220a1391af547aaa
description: MuleSoft Documentation Site
latest: true
---
---
product: Mule Gateway
---

# HTTP Policy Transform Extension

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

In Mule version 4.1.0 and later, the HTTP Policy Transform Extension is available for use in
policies. This extension simplifies the modification of HTTP requests and responses that go through
the different policies. This documentation applies to HTTP Policy Transform Extension 3.0.0 and
later.

## Adding the extension as a Maven dependency to a policy

To use the HTTP Policy Transform Extension in a policy, first you must add the Maven dependency to
the POM file of the policy. Add the following code in the dependencies section of policy’s POM file:

```xml
  <dependency>
      <groupId>com.mulesoft.anypoint</groupId>
      <artifactId>mule-http-policy-transform-extension</artifactId>
      <version>${httpPolicyTransformVersion}</version>
      <classifier>mule-plugin</classifier>
      <exclusions>
          <exclusion>
              <groupId>org.mule.connectors</groupId>
              <artifactId>mule-http-connector</artifactId>
          </exclusion>
      </exclusions>
  </dependency>
```

When a policy using the HTTP Policy Transform Extension is packaged, the Mule HTTP Connector is
added to the policy JAR file. To avoid double packaging the connector in both your policy and
application, use the exclusion statement in the dependency to remove the Mule HTTP Connector from
the policy JAR file. However, if your custom policy must perform its own outbound HTTP requests, you
must either:

- Remove the exclusion statement to ensure the connector is available within the policy’s own class
  loader.

- Set `mule.enable.policy.isolation=false` so that the policy uses the application level connector.

Additionally, ensure that you set the `mule-maven-plugin` parameter version to `3.3.2` or later in
the POM file of the policy.

## Namespace

```xml
<mule
xmlns:http-transform="http://www.mulesoft.org/schema/mule/http-policy-transform"

xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/http-policy-transform http://www.mulesoft.org/schema/mule/http-policy-transform/current/mule-http-policy-transform.xsd">
```

## Operations

- Add Headers Operations

  - Add Request Headers

  - Add Request Headers List (Since mule-http-policy-transform-extension 3.1.0)

  - Add Response Headers

  - Add Response Headers List (Since mule-http-policy-transform-extension 3.1.0)

- Remove Headers

- Set Response

- Set Request

### Add Headers Operations

#### Add Request Headers

This operation is used to inject headers in the request. To use this operation, you must initiate a
call from:

- Source Policy, before the `execute-next` is invoked.

- Operation Policy, before the `execute-next` is invoked.

##### Parameters

- `headers`

  A DataWeave expression that resolves to the Map of the headers to be added to present message
  attributes.

  **Example**

  ```xml
  <http-transform:add-request-headers>
  <http-transform:headers>#[
  {
    'FirstHeader': 'FirstHeaderValue',
    'SecondHeader': 'SecondHeaderValue',
    'ThirdHeader': 'ThirdHeaderValue'
  }
  ]</http-transform:headers>
  </http-transform:add-request-headers>
  ```

#### Add Request Headers List

> [!NOTE] This operation was added in mule-http-policy-transform-extension 3.1.0.

This operation is used to inject headers in the request. To use this operation, you must initiate a
call from:

- Source Policy, before `execute-next` is invoked.

- Operation Policy, before `execute-next` is invoked.

##### Parameters

- `http-transform:new-headers`

  An `http-transform:header` must be added for each header. Each http-transform:header must have the
  `headerName` and `headerValue` attributes defined with a literal or a DataWeave expression.

  **Example**

  ```xml
  <http-transform:add-request-headers-list>
      <http-transform:new-headers>
          <http-transform:header headerName="FirstHeader" headerValue="FirstHeaderValue"/>
          <http-transform:header headerName="#['SecondHeader']" headerValue="#['SecondHeaderValue']"/>
          <http-transform:header headerName="ThirdHeader" headerValue="ThirdHeaderValue"/>
      </http-transform:new-headers>
  </http-transform:add-request-headers-list>
  ```

The operation allows DataWeave expressions when the policy configuration has a property type of
`keyvalues` with multiple values.

**Example**

```xml
...
configuration:
  - propertyName: requestHeaders
    name: Reques Headers
    description: Header Names and values
    type: keyvalues
    optional: true
    allowMultiple: true
...
```

With the above configuration shown, you can use handlebars to expand the headers to be added in the
policy:

```xml
...
<http-transform:add-request-headers-list>
    <http-transform:new-headers>
        {{#each requestHeaders}}
        <http-transform:header headerName="{{{this.key}}}" headerValue="{{{this.value}}}"/>
        {{/each}}
    </http-transform:new-headers>
</http-transform:add-request-headers-list>
...
```

#### Add Response Headers

This operation is used to inject headers in the response. To use this operation, you must initiate a
call from:

- Source Policy, after the `execute-next` is invoked.

- Operation Policy, after the `execute-next` is invoked.

##### Parameters

- `headers`

  A DataWeave expression that resolves to the Map of headers to be added to present message
  attributes.

  **Example**

  ```xml
  <http-transform:add-response-headers>
  <http-transform:headers>#[
  {
    'FirstHeader': 'FirstHeaderValue',
    'SecondHeader': 'SecondHeaderValue',
    'ThirdHeader': 'ThirdHeaderValue'
  }
  ]</http-transform:headers>
  </http-transform:add-response-headers>
  ```

#### Add Response Headers List

> [!NOTE] This operation was added in mule-http-policy-transform-extension 3.1.0.

This operation is used to inject headers in the response. To use this operation, you must initiate a
call from:

- Source Policy, after the `execute-next` is invoked.

- Operation Policy, after the `execute-next` is invoked.

##### Parameters

- `http-transform:new-headers`

  An `http-transform:header` must be added for each header. Each http-transform:header must have the
  `headerName` and `headerValue` attributes defined with a literal or a DataWeave expression.

  **Example**

  ```xml
  <http-transform:add-response-headers-list>
      <http-transform:new-headers>
          <http-transform:header headerName="FirstHeader" headerValue="FirstHeaderValue"/>
          <http-transform:header headerName="#['SecondHeader']" headerValue="#['SecondHeaderValue']"/>
          <http-transform:header headerName="ThirdHeader" headerValue="ThirdHeaderValue"/>
      </http-transform:new-headers>
  </http-transform:add-response-headers-list>
  ```

The operation allows DataWeave expressions when the policy configuration has a property of type
`keyvalues` with multiple values.

**Example**

```xml
...
configuration:
  - propertyName: responseHeaders
    name: Reques Headers
    description: Header Names and values
    type: keyvalues
    optional: true
    allowMultiple: true
...
```

With the above configuration shown, you can use handlebars to expand the headers to be added in the
policy:

```xml
...
<http-transform:add-reponse-headers-list>
    <http-transform:new-headers>
        {{#each responseHeaders}}
        <http-transform:header headerName="{{{this.key}}}" headerValue="{{{this.value}}}"/>
        {{/each}}
    </http-transform:new-headers>
</http-transform:add-response-headers-list>
...
```

### Remove Headers

This operation removes the headers from both requests and responses of the HTTP Listener and
Requester. The returned attributes are of the same type as that of the input attributes. This
operation is case-insensitive.

#### Parameters

- `header-names`

  A Data-Weave expression that resolves to an array of header names to be removed.

  **Example**

  ```xml
  <http-transform:remove-headers>
      <http-transform:header-names>#[['FirstHeader', 'SecondHeader']]</http-transform:header-names>
  </http-transform:remove-headers>
  ```

### Set Response

This operation sets a complete HTTP response. You use this operation when the policy prevents the
flow from being executed, thereby resulting in no HTTP response being set.

#### Parameters

- `statusCode`\-- An integer representing the HTTP status code of the response.

- `reasonPhrase`\-- A string representing the HTTP reason phrase of the response.

- `body`\-- The content of the HTTP response.

- headers-- A DataWeave expression that resolves to the map of headers of the HTTP response

  **Example**

  ```xml
  <http-transform:set-response statusCode="203" reasonPhrase="policyReasonPhrase">
      <http-transform:body>#['policyPayload']</http-transform:body>
      <http-transform:headers>#[
          {
              'FirstHeader': 'FirstHeaderValue',
              'SecondHeader': 'SecondHeaderValue',
              'ThirdHeader': 'ThirdHeaderValue'
          }
      ]</http-transform:headers>
  </http-transform:set-response>
  ```

### Set Request

This operation sets a complete HTTP request that the HTTP Requester executes.

#### Parameters

- `requestPath`: The path where the HTTP Request is being sent.

- `body`: The content of the HTTP Request.

- `headers`: A DataWeave expression that resolves to the map of headers of the HTTP request.

- `uriParams`: A DataWeave expression that resolves to the map of URI params of the HTTP request.

- `queryParams`: A DataWeave expression that resolves to the map of query params of the HTTP
  request.

  **Example**

  ```xml
  <http-transform:set-requester-request requestPath="/backend/policy/{policyUriParam}">
      <http-transform:body>#['policyPayload']</http-transform:body>
      <http-transform:headers>#[
          {
              'FirstHeader': 'FirstHeaderValue',
              'SecondHeader': 'SecondHeaderValue',
              'ThirdHeader': 'ThirdHeaderValue'
          }
      ]</http-transform:headers>
      <http-transform:uri-params>#[
          {
              'FirstUriParam': 'FirstUriParamValue',
              'SecondUriParam': 'SecondUriParamValue'
          }
      ]</http-transform:uri-params>
      <http-transform:query-params>#[
          {
              'FirstQueryParam': 'FirstQueryParamValue',
              'SecondQueryParam': 'SecondQueryParamValue'
          }
      ]</http-transform:query-params>
  </http-transform:set-requester-request>
  ```
