Layer7 API Management

  • 1.  Custom Assertion accessing request/response headers

    Posted Oct 28, 2015 11:20 AM

    Hi,

     

    I have a question regarding the Custom Assertion SDK.

    Is there a way to access the headers on a request and response message that are added by assertions within my policy?


    In a custom assertion, we read the request and response headers using the CustomPolicyContext by calling the

    CustomPolicyContext.getMessage method in an extension of the ServiceInvocation checkRequest method.

     

    E.g: context.getMessage("request").getKnob(CustomHttpHeadersKnob.class).getHeaderNames()

     

    Request headers that are set from the client are accessible this way, but we can't see any additional headers that are set on the request or response with a "Manage Transport Properties/Headers" assertion in the executing policy.

    It seems like the message retrieved by the getMessage("request") or getMessage("response") are not the actual updated messages at the execution point of my custom assertion.

    When using the Service Debugger in the Policy Manager, I can see that the headers are added to the request and response, but in my custom assertion they are not.

     

    I don't know the names of the headers, so I must be able to use the knob.getHeaderNames() and loop it with getHeaderValues() accordingly or a similar approach.

     

    Thanks,

    Tony



  • 2.  Re: Custom Assertion accessing request/response headers
    Best Answer

    Posted Oct 29, 2015 12:13 PM

    I found a workaround for this by using getVariable("<target>.http.allheadervalues") and doing a lot of awkward parsing and looping, since it returns String or Object[] with "name:value" pattern.