1 <?xml version="1.0" encoding="UTF-8" ?>
2 <!DOCTYPE manualpage SYSTEM "./style/manualpage.dtd">
3 <?xml-stylesheet type="text/xsl" href="./style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
7 Licensed to the Apache Software Foundation (ASF) under one or more
8 contributor license agreements. See the NOTICE file distributed with
9 this work for additional information regarding copyright ownership.
10 The ASF licenses this file to You under the Apache License, Version 2.0
11 (the "License"); you may not use this file except in compliance with
12 the License. You may obtain a copy of the License at
14 http://www.apache.org/licenses/LICENSE-2.0
16 Unless required by applicable law or agreed to in writing, software
17 distributed under the License is distributed on an "AS IS" BASIS,
18 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 See the License for the specific language governing permissions and
20 limitations under the License.
23 <manualpage metafile="expr.xml.meta">
25 <title>Expressions in Apache</title>
28 <p>Historically, there are several syntax variants for expressions used to express
29 a condition in the different modules of the Apache HTTP Server.
30 There is some ongoing effort to only use a single variant, called <em>ap_expr</em>,
31 for all configuration directives.
32 This document describes the <em>ap_expr</em> expression parser.
36 <section id="grammar">
37 <title>Grammar in BNF notation</title>
40 expr ::= "<strong>true</strong>" | "<strong>false</strong>"
41 | "<strong>!</strong>" expr
42 | expr "<strong>&&</strong>" expr
43 | expr "<strong>||</strong>" expr
44 | "<strong>(</strong>" expr "<strong>)</strong>"
51 | word "<strong>in</strong>" "<strong>{</strong>" wordlist "<strong>}</strong>"
52 | word "<strong>in</strong>" listfunction
53 | word "<strong>=~</strong>" regex
54 | word "<strong>!~</strong>" regex
57 stringcomp ::= word "<strong>==</strong>" word | word "<strong>eq</strong>" word
58 | word "<strong>!=</strong>" word | word "<strong>ne</strong>" word
59 | word "<strong><</strong>" word | word "<strong>lt</strong>" word
60 | word "<strong><=</strong>" word | word "<strong>le</strong>" word
61 | word "<strong>></strong>" word | word "<strong>gt</strong>" word
62 | word "<strong>>=</strong>" word | word "<strong>ge</strong>" word
64 integercomp ::= word "<strong>-eq</strong>" word | word "<strong>eq</strong>" word
65 | word "<strong>-ne</strong>" word | word "<strong>ne</strong>" word
66 | word "<strong>-lt</strong>" word | word "<strong>lt</strong>" word
67 | word "<strong>-le</strong>" word | word "<strong>le</strong>" word
68 | word "<strong>-gt</strong>" word | word "<strong>gt</strong>" word
69 | word "<strong>-ge</strong>" word | word "<strong>ge</strong>" word
72 | wordlist "<strong>,</strong>" word
74 word ::= word "<strong>.</strong>" word
76 | "<strong>'</strong>" string "<strong>'</strong>"
77 | "<strong>"</strong>" string "<strong>"</strong>"
84 stringpart ::= cstring
90 variable ::= "<strong>%{</strong>" varname "<strong>}</strong>"
91 | "<strong>%{</strong>" funcname "<strong>:</strong>" funcargs "<strong>}</strong>"
93 function ::= funcname "<strong>(</strong>" word "<strong>)</strong>"
95 listfunction ::= listfuncname "<strong>(</strong>" word "<strong>)</strong>"
102 <title>Variables</title>
103 <p>XXX: not all vars are available in all request phases</p>
105 <p>Request headers (XXX:see req function)</p>
107 <table border="1" style="zebra">
108 <columnspec><column width="1"/></columnspec>
110 <tr><th>Name</th></tr>
111 <tr><td><code>HTTP_ACCEPT</code></td></tr>
112 <tr><td><code>HTTP_FORWARDED</code></td></tr>
113 <tr><td><code>HTTP_HOST</code></td></tr>
114 <tr><td><code>HTTP_PROXY_CONNECTION</code></td></tr>
115 <tr><td><code>HTTP_REFERER</code></td></tr>
116 <tr><td><code>HTTP_USER_AGENT</code></td></tr>
120 <p>Other request related variables</p>
122 <table border="1" style="zebra">
123 <columnspec><column width=".4"/><column width=".6"/></columnspec>
125 <tr><th>Name</th><th>Description</th></tr>
126 <tr><td><code>REQUEST_METHOD</code></td>
128 <tr><td><code>REQUEST_SCHEME</code></td>
130 <tr><td><code>REQUEST_URI</code></td>
132 <tr><td><code>REQUEST_FILENAME</code></td>
134 <tr><td><code>REMOTE_HOST</code></td>
136 <tr><td><code>REMOTE_IDENT</code></td>
138 <tr><td><code>REMOTE_USER</code></td>
140 <tr><td><code>SERVER_ADMIN</code></td>
142 <tr><td><code>SERVER_NAME</code></td>
144 <tr><td><code>SERVER_PORT</code></td>
146 <tr><td><code>SERVER_PROTOCOL</code></td>
148 <tr><td><code>SCRIPT_FILENAME</code></td>
150 <tr><td><code>PATH_INFO</code></td>
152 <tr><td><code>QUERY_STRING</code></td>
154 <tr><td><code>IS_SUBREQ</code></td>
156 <tr><td><code>DOCUMENT_ROOT</code></td>
158 <tr><td><code>AUTH_TYPE</code></td>
160 <tr><td><code>THE_REQUEST</code></td>
162 <tr><td><code>CONTENT_TYPE</code></td>
164 <tr><td><code>HANDLER</code></td>
166 <tr><td><code>REMOTE_ADDR</code></td>
168 <tr><td><code>HTTPS</code></td>
170 <tr><td><code>IPV6</code></td>
175 <p>Misc variables</p>
177 <table border="1" style="zebra">
178 <columnspec><column width=".4"/><column width=".6"/></columnspec>
180 <tr><th>Name</th><th>Description</th></tr>
181 <tr><td><code>TIME_YEAR</code></td>
183 <tr><td><code>TIME_MON</code></td>
185 <tr><td><code>TIME_DAY</code></td>
187 <tr><td><code>TIME_HOUR</code></td>
189 <tr><td><code>TIME_MIN</code></td>
191 <tr><td><code>TIME_SEC</code></td>
193 <tr><td><code>TIME_WDAY</code></td>
195 <tr><td><code>TIME</code></td>
197 <tr><td><code>SERVER_SOFTWARE</code></td>
199 <tr><td><code>API_VERSION</code></td>
206 <title>Binary operators</title>
208 <p>With the exception of some built-in comparison operators, binary
209 operators have the form "<code>-[a-zA-Z][a-zA-Z0-9_]+</code>", i.e. a
210 minus and at least two characters. The name is not case sensitive.
211 Modules may register additional binary operators.</p>
213 <table border="1" style="zebra">
214 <columnspec><column width=".2"/><column width=".2"/><column width=".6"/></columnspec>
216 <tr><th>Name</th><th>Alternative</th> <th>Description</th></tr>
217 <tr><td><code>==</code></td>
218 <td><code>=</code></td>
219 <td>String equality</td></tr>
220 <tr><td><code>!=</code></td>
222 <td>String inequality</td></tr>
223 <tr><td><code><</code></td>
225 <td>String less than</td></tr>
226 <tr><td><code><=</code></td>
228 <td>String less than or equal</td></tr>
229 <tr><td><code>></code></td>
231 <td>String greater than</td></tr>
232 <tr><td><code>>=</code></td>
234 <td>String greater than or equal</td></tr>
235 <tr><td><code>-eq</code></td>
236 <td><code>eq</code></td>
237 <td>Integer equality</td></tr>
238 <tr><td><code>-ne</code></td>
239 <td><code>ne</code></td>
240 <td>Integer inequality</td></tr>
241 <tr><td><code>-lt</code></td>
242 <td><code>lt</code></td>
243 <td>Integer less than</td></tr>
244 <tr><td><code>-le</code></td>
245 <td><code>le</code></td>
246 <td>Integer less than or equal</td></tr>
247 <tr><td><code>-gt</code></td>
248 <td><code>gt</code></td>
249 <td>Integer greater than</td></tr>
250 <tr><td><code>-ge</code></td>
251 <td><code>ge</code></td>
252 <td>Integer greater than or equal</td></tr>
258 <title>Unary operators</title>
260 <p>Unary operators have the form "<code>-[a-zA-Z]</code>", i.e. a
261 minus and one character. The name <em>is</em> case sensitive.
262 Modules may register additional unary operators.</p>
264 <table border="1" style="zebra">
265 <columnspec><column width=".2"/><column width=".2"/><column width=".6"/></columnspec>
267 <tr><th>Name</th><th>Description</th></tr>
268 <tr><td><code>-n</code></td>
269 <td>String is not empty</td></tr>
270 <tr><td><code>-z</code></td>
271 <td>String is empty</td></tr>
276 <section id="functions">
277 <title>Functions</title>
279 <p>Normal string-valued functions take one string as argument and return
280 a string. Functions names are not case sensitive.
281 Modules may register additional functions.</p>
283 <table border="1" style="zebra">
284 <columnspec><column width=".2"/><column width=".8"/></columnspec>
286 <tr><th>Name</th><th>Description</th></tr>
287 <tr><td><code>req</code>, <code>http</code></td>
288 <td>Get HTTP request header</td></tr>
289 <tr><td><code>resp</code></td>
290 <td>Get HTTP response header</td></tr>
291 <tr><td><code>reqenv</code></td>
292 <td>Lookup request environment variable</td></tr>
293 <tr><td><code>osenv</code></td>
294 <td>Lookup operating system environment variable</td></tr>
295 <tr><td><code>note</code></td>
296 <td>Lookup request environment variable</td></tr>
297 <tr><td><code>env</code></td>
298 <td>Reqturn first match of <code>note</code>, <code>reqenv</code>,
299 <code>osenv</code></td></tr>
300 <tr><td><code>tolower</code></td>
301 <td>Convert string to lower case</td></tr>
302 <tr><td><code>toupper</code></td>
303 <td>Convert string to uppser case</td></tr>
304 <tr><td><code>escape</code></td>
305 <td>Escape special characters in %hex encoding</td></tr>
306 <tr><td><code>unescape</code></td>
307 <td>Unescape %hex encoded string, leaving URL-special characters encoded (XXX: describe better)</td></tr>
308 <tr><td><code>file</code></td>
309 <td>Read contents from a file</td></tr>
312 <p>In addition to string-valued functions, there are also list-valued functions which
313 take one string as argument and return a wordlist, i.e. a list of strings. The wordlist
314 can be used with the special <code>-in</code> operator.
315 Functions names are not case sensitive.
316 Modules may register additional functions.</p>
318 <p>There are no built-in list-valued functions. mod_ssl provides
319 <code>PeerExtList</code> (XXX: link)</p>