Search code examples
mulemule-componentmule-esbmule4

Deleting headers from request-config instead of flow in MULE 4


I'm trying to find solution for deleting request headers in MULE 4 by more effective way then actual. In request config is possible to have <http:default-headers />, but I can't find way to delete headers from here. So I'm deleting headers in flow -> like this:

    <http:headers>#[attributes.headers -- ["host", "http.headers"]]</http:headers>

Full version of flow is here:

<flow name="WS_name">
<http:listener path="someway/*" config-ref="External_Listener" doc:name="HTTP">
    <http:response statusCode="#[vars.httpStatus default 200]">
        <http:headers>#[vars.outboundHeaders default {}]</http:headers>
    </http:response>
    <http:error-response statusCode="#[vars.httpStatus default 500]">
        <http:body>#[payload]</http:body>
        <http:headers>#[vars.outboundHeaders default {}]</http:headers>
    </http:error-response>
</http:listener>
<http:request method="#[attributes.method]" sendBodyMode="AUTO" config-ref="HTTPS_Request_configuration_proxy" url="#['https://${endpoint.WS_name.host}:${endpoint.WS_name.port}' ++ '${endpoint.WS_name.path}/']">
    <http:headers>#[attributes.headers -- ["host", "http.headers"]]</http:headers>
</http:request>

If anyone have better solution, please, share it.


Solution

  • What you are doing is fine. If you want to do that in the flow outside of the http:request, then you can. All the http:headers expects is a map. So here is an example of using a var:

    <set-variable variableName="myAttributes" value="#[attributes.headers -- ['host', 'http.headers']]" />
    
    <http:request method="#[attributes.method]" sendBodyMode="AUTO" config-ref="HTTPS_Request_configuration_proxy"
                url="#['https://${endpoint.WS_name.host}:${endpoint.WS_name.port}' +++ '${endpoint.WS_name.path}/']">
                <http:headers>#[vars.myAttributes]</http:headers>
    </http:request>