Conditional Steps in a request/response flow

I am validating 'Content-Type' header in my api proxy using the following two steps:

<!-- validate content type -->
<Step>
    <Condition>request.header.Content-Type != "application/x-www-form-urlencoded"</Condition>
    <Name>AssignMessage.Error.InvalidContentType</Name>
</Step>
<Step>
    <Condition>request.header.Content-Type != "application/x-www-form-urlencoded"</Condition>
    <Name>RaiseFault.GoToFaultRules</Name>
</Step>

This works fine if the Content-Type header contains only type/sub-type without the optional ';parameter'. How can I modify the above test to check the header value for only the type/sub-type and ignore the optional parameter -- without dropping out to java script?

1 6 3,714
6 REPLIES 6

I believe you could do this with a regex. (Insert joke about having two problems now.)

http://docs.apigee.com/api-services/reference/conditions-reference

The java regex operator is `~~`

Thanks - I am looking at the document. I thought '=|' (starts with) would have worked equally if I could add ! to negate the operator. I am managing to get some bizarre errors when I do this -- my API goes in a semi deployed state, reports of unknown errors, unable to undeploy/redeploy the proxy etc...

I have used StartsWith, Matches, and JavaRegex (~~).

They all work. I believe the bizarre problems you saw were likely coincidental, and unrelated.

Sorry to hear about those, but ... i think your pattern matching question is entirely independent.

I would like to think the problems are unrelated and what I am doing is perfectly legitimate, although I am doubtful due to the consistency with which the errors happen. At one point, I did manage to add !~ (not Matches/Like), however the proxy performance suffered immensely. Again this may be coincidental and a result of general issues with the platform or it may be because of changes I have made. Hard to tell. I am slowly coming to the conclusion that this will be much simpler to do in a java script.

It would be disappointing to me, if you came to the conclusion that you needed Javascript to check a request header. But it would work just fine, also. If that's what you want to do, by all means !

I can say only that it works for me. I use all of the above options, regularly , and never see a performance difference in any of them.

What kind of load are you running through the system, when you detect a performance difference?

great question! I had this problem just the other day.