<div dir="ltr"><div><div><div>A fairly common requirement for web requests is to enable or disable a certain action based on the state of the request. e.g:<br>- disable compression if the response &gt; 10Mb<br>- If the user agent is X add header Y<br>
- If the path starts with /private disable caching<br>etc<br><br>To enable us to acomplish this Undertow has the concept of predicates[1], which as you would expect are a function object that takes the exchange as an argument and returns a boolean value. <br>
<br>We also provide boolean operator predicates (and, or, not) that allow you to combine these predicates into arbitrarily complex values. The idea is that if a user want to configure a conditional action on the request they will use these predicates to specify the condition. <br>
<br>To that end we need some way of representing them in the Wildfly configuration file, and so I have hacked up a basic syntax to configure them, and I would like some feedback. The configuration syntax will written directly into the standalone.xm and jboss-web.xmll to conditionally enable handlers. <br>
<br>A basic example looks like:<br>                                                                                                                                   <br>path[&quot;/MyPath&quot;] or (method[value=&quot;POST&quot;] and not requestHeadersPresent[value={Content-Type, &quot;Content-Encoding&quot;}, ignoreTrailer=true] )                                                                                <br>
                                                                                                                                      <br>The following boolean operators are built in, listed in order or precedence:                                                               <br>
- not                                                                                                                                      <br>- and                                                                                                                                      <br>
- or      <br>                                                                                                                                   <br>They work pretty much as you would expect them to. All other tokens are taken                                                              <br>
to be predicate names. If the predicate does not require any parameters then the                                                           <br>brackets can be omitted, otherwise they are mandatory.                                                      <br>
                                                                                                                               <br>If a predicate is only being passed a single parameter then the parameter name can be omitted.                                             <br>
Strings can be enclosed in optional quotations marks, and quotation marks can be escaped using \&quot;                                                                                                                       <br>
                                                                                                                                  <br>Array types are represented via a comma separated list of values enclosed in curly braces.<br>
<br></div>Predicate definitions themselves are loaded via a service loader mechanim, with the service implementation specifying the name and the parameter types. <br></div><br></div>I would be interested to hear what people think. At the moment this is very simple, however a by product of this simplicity is that you need multiple predicates to handle similar things (e.g. requestHeadersPresent, responseHeadersPresent, requestHeaderContains, requestHeaderEquals etc).<br>
<div><div><div><br>[1] <a href="https://github.com/undertow-io/undertow/tree/master/core/src/main/java/io/undertow/predicate">https://github.com/undertow-io/undertow/tree/master/core/src/main/java/io/undertow/predicate</a><br>
</div></div></div></div>