Daily Archives: March 31, 2008

Expression parser for Apache

Over the past few days I’ve got a long-awaited round tuit, and given Apache a general-purpose expression parser, ap_expr. That’s in trunk/2.3, and is unlikely to be stable enough for a 2.2.x (release) version for a while.

What I haven’t done this time is write a new expression parser. I’ve done that before, e.g. when I hacked up an ESI parser in 2003, but it’s necessarily an exercise in reinventing the wheel. So this time I’ve just adapted an existing parser: the one used by mod_include. That basically meant removing mod_include-specific stuff from its expression parser, and generalising somewhat. The first stage was complete when mod_include itself was adapted to use ap_expr, and passed all tests with it.

The second module I’ve just now adapted is mod_filter, where the expression parser replaces the ad-hoc dispatch criteria in the FilterProvider directive. The advantage of this is that the updated mod_filter can dispatch on multiple criteria. For example, a user wants a filter to apply if and only if the Content Type is text/html AND the response is not compressed. That’s now easy, and no longer requires hackish workarounds:

FilterProvider myname myprovider "($resp{Content-Encoding} != gzip) && ($Content-Type == /text\/html/i)"

In the medium term, this could be used to enhance a number of different apache functions, and provide a more consistent expression syntax across different modules. Notable potential benefits include a far simpler and more logical configuration syntax for some of the more complex tasks undertaken with mod_rewrite.

Follow

Get every new post delivered to your Inbox.

Join 35 other followers