Uploaded image for project: 'Undertow'
  1. Undertow
  2. UNDERTOW-2120

Predicate Language exchange attribute transformers (like lower case)

XMLWordPrintable

    • Icon: Feature Request Feature Request
    • Resolution: Unresolved
    • Icon: Major Major
    • 2.4.0.Final
    • None
    • Predicate Language
    • None

      I was helping a developer convert some IIS rewrite rules over to use Undertow's predicate language and I found something interesting.  Here is an excerpt from an IIS rewrite.
       

      <rule name="LowerCase Rule" stopProcessing="true">
        <match url="[A-Z]" ignoreCase="false" />
        <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
          <add input="{URL}" pattern="^.*\.(css|js|jpg|jpeg|png|gif|pdf|csv|xml|ttf|eot|svg|woff|ico|woff2|json|swf|xap|cfm)$" ignoreCase="true" negate="true" />
        </conditions>
        <action type="Redirect" url="{ToLower:{URL}}" redirectType="Permanent" />
      </rule>

       
      The interesting part here being the {ToLower:{URL}}
       
      Undertow's Predicate language doesn't appear to have any sort of basic string manipulation functions like lower or upper casing.
       
      It would appear IIS's rewrite module has out-of-the-box support for the following "string functions"

      • toLower
      • UrlEncode
      • UrlDecode

      which is quite odd that I don't see a "toUpper" in there!  
       
      https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-configuration-reference#string-functions
       
      I recommend implementing these as exchange attributes themselves which can wrap another attribute (decorator pattern) in the format of

      %{NameHere:attribute-to-wrap}
      

      So an example would be:

      %{toLower:%{METHOD}}
      

      This would allow recursive nesting of transformations like so:

      %{URLDecode:%{toLower:%{i,myHeader}}}

      Please note, the exchange attribute parser needs a fix applied to allow parsing of an attribute that nests another attribute. https://issues.redhat.com/browse/UNDERTOW-2273

            mjusko@redhat.com Marek Jusko
            bdw429s Brad Wood (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: