title: Mule 4 Custom Policy Adding Request Headers Dynamically
body: <p>I am very new to Mulesoft and an entry-level programmer. I have been trying to figure out how to implement Mule 4 custom policies. This is the online documentation: <a href="https://docs.mulesoft.com/api-manager/2.x/http-policy-transform#add-headers" rel="nofollow noreferrer">https://docs.mulesoft.com/api-manager/2.x/http-policy-transform#add-headers</a></p>
  
  <p>Following the examples, I was successfully able to add request and response headers. My main goal is to add the request headers while using variables. I am trying MEL (<a href="https://docs.mulesoft.com/mule-runtime/3.7/mule-expression-language-examples" rel="nofollow noreferrer">https://docs.mulesoft.com/mule-runtime/3.7/mule-expression-language-examples</a>) to try to call the variable names but it doesn't work. HOWEVER, whenever I try logging the variables it returns the correct value. </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;mule xmlns="http://www.mulesoft.org/schema/mule/core"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:http-policy="http://www.mulesoft.org/schema/mule/http-policy"
        xmlns:http-transform="http://www.mulesoft.org/schema/mule/http-policy-transform"
        xmlns:secure-properties="http://www.mulesoft.org/schema/mule/secure-properties"
        xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
                 http://www.mulesoft.org/schema/mule/http-policy http://www.mulesoft.org/schema/mule/http-policy/current/mule-http-policy.xsd
                 http://www.mulesoft.org/schema/mule/http-policy-transform http://www.mulesoft.org/schema/mule/http-policy-transform/current/mule-http-policy-transform.xsd
                 http://www.mulesoft.org/schema/mule/secure-properties http://www.mulesoft.org/schema/mule/secure-properties/current/mule-secure-properties.xsd"&gt;
  
      &lt;http-policy:proxy name="{{{policyId}}}-custom-policy"&gt;
          &lt;http-policy:source propagateMessageTransformations="true"&gt;
              &lt;try&gt;
                  &lt;set-variable variableName="header" value="TEST_HEADER"/&gt;
                  &lt;logger level="INFO" message="#[vars.header]" /&gt;
                  &lt;http-transform:add-headers outputType="request"&gt;
                      &lt;http-transform:headers&gt;#[{'TEST_HEADER': 'TEST'}]&lt;/http-transform:headers&gt;
                  &lt;/http-transform:add-headers&gt;
                  &lt;http-policy:execute-next/&gt;
                  &lt;http-transform:add-headers outputType="response"&gt;
                      &lt;http-transform:headers&gt;#[{'Header_Added': '#[vars.header]'}]&lt;/http-transform:headers&gt;
                      #this step doesn't work as I hoped it would
                  &lt;/http-transform:add-headers&gt;
                  &lt;logger level="INFO" message="#[vars.header]" /&gt;
                  #logging prints the value of header
               &lt;/try&gt;
          &lt;/http-policy:source&gt;
      &lt;/http-policy:proxy&gt;
  &lt;/mule&gt;
  </code></pre>
  
  <p>I am trying to add <code>#[vars.header]</code> as a request header name and possibly the value? Would I need to create another variable to have the header value? Can someone please guide me the right direction? </p>
  
  <p>Thank you</p>