How do I verify required header params, Extract variables does not raise a fault for a missing header param?

I want to get require certain header params in all my requests and extract them to variables. Seems like an easy thing to do with Extract Variables, but it doesn't raise a fault if a param is missing, it does if a payload element is missing.

Why not for other params?

Sure, I can put a condition after the Extract Variables and Raise Fault there, but seems like I should not have to do that.

1 2 3,428
2 REPLIES 2

Not applicable

By default headers are automatically (implicitly) extracted into variables. You can access them (read or write) by using the variable name "request.header.NAME" where NAME is replaced with the header of your choice. For example Content-Type, or Authorization, etc. It is unnecessary to use the ExtractVariables policy for this purpose.

If you want to make sure that a header exists you need a RaiseFault policy with a condition checking that variable. For example:

<Step>
  <Name>RaiseFaultWhenMissingRequiredHeaders<Name>
  <Condition>(request.header.somerequiredheader != null) or (request.header.someotherrequiredheader != null)</Condition>
</Step>

Note:

You might ask why we have the headers section in the extract variables policy. It is intended to be used when extract data out of a complex header value think comma delimited values or something similar.

Thanks,

I'm getting them as variables as I need them to compute an HMAC for message validation later and it makes things a bit clearer. Perhaps I can fine tune later for performance.

<Condition>(mycontext.hmac = null) or (mycontext.nonce = null)</Condition>

Right, like if I want to get the value from Authorization: HMAC KJ45LKJELR9J09DJFDIJ8F.

Still, it would be nice if EV could raise fault in this situation, or at least have an option to do so.

Thanks