2

I want to understand the concept of default header in mule.I want to hit a get api call[the code is written in java] from mule and I am sending a token in the header, but I am setting the token in the default header inside the http request configuration.

<http:default-headers >
            <http:default-header key="testing" value="#[vars.authorizationHeader]" />
        </http:default-headers>

Will my java code be able to read this header from attributes ?

HMT
  • 2,093
  • 1
  • 19
  • 51

1 Answers1

5

Default headers are just ones that will always be sent across all requests referencing that configuration, so yes, your server will get that token. However, it is not a good practice to use them along with expressions as you are doing because that makes the configuration very fragile (what if there's no such var in the request flow?) and force a new configuration to be used (as the expression must be resolved each time). Default headers make sense when you want to force a static header everywhere, for tracking purposes for example. If the header will be dynamic, then it's best to configure it on each request.

afelisatti
  • 2,770
  • 1
  • 13
  • 21
  • But when I was debugging, the deafult header was set inside request-config-defaultHeaders and attributes were null – HMT Feb 22 '20 at 13:03
  • 1
    The values will be resolved and used internally so I'm not sure what you'll see while debugging. I'd recommend using something like httpbin.org to check the headers the server gets (there's a /headers endpoint for that purpose). – afelisatti Feb 25 '20 at 15:13
  • https://stackoverflow.com/questions/64388403/connect-timeout-error-on-cloudhub-mule-version4-2-2 . Can you please help me with this question ? – HMT Oct 16 '20 at 13:33