Skip to content

Commit 13ee0cd

Browse files
mlibbeyMiles Libbey
andauthored
Add some more hrw4u help (#12286)
Added a missing python requirement, and a few more steps to get hrw4u to build for the first time. Also included a few more doc hints on usage. Co-authored-by: Miles Libbey <mlibbey@apple.com>
1 parent 57d73b7 commit 13ee0cd

4 files changed

Lines changed: 35 additions & 6 deletions

File tree

doc/admin-guide/configuration/hrw4u.en.rst

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ virtualenv or system-wide using:
6767

6868
.. code-block:: none
6969
70-
pip install dist/hrw4u-1.0.0-py3-none-any.whl
70+
pipx install dist/hrw4u-1.0.0-py3-none-any.whl
7171
7272
Using
7373
-----
@@ -91,7 +91,8 @@ Syntax Differences
9191
The basic structure is a `section` name defining the part of the transaction to run in
9292
followed by conditionals and operators. It uses `if () {} else {}` conditional syntax
9393
with `&& , || and ==`, with conditions and operators generally following function() or
94-
object.style grammar. For instance:
94+
object.style grammar. Operator lines are terminated with `;` (whitespace is still not
95+
significant). For instance:
9596

9697
.. code-block:: none
9798
@@ -167,6 +168,7 @@ cond %{SSN-TXN-COUNT} >10 ssn-txn-count() > 10 Number of tra
167168
cond %{TO-URL:<C>} =bar to.url.<C> == "bar" Remap ``To URL`` component match, ``C`` is ``host`` etc.
168169
cond %{TXN-COUNT} >10 txn-count() > 10 Number of transactions on client connection
169170
cond %{URL:<C> =bar {in,out}bound.url.<C> == "bar" Context aware URL component match
171+
cond ${GEO:<C>} =bar geo.<C> == "bar" IP to Geo mapping. ``C`` is ``country``, ``asn`` etc.
170172
=============================== ================================== ================================================
171173

172174
The conditions operating on headers and URLs are also available as operators. E.g.:
@@ -180,10 +182,14 @@ The conditions operating on headers and URLs are also available as operators. E.
180182
In general, where it makes sense for the condition to be used as an operator, it is available as an operator.
181183
The rule of thumb is the conditional is an operator if the value is mutable.
182184

185+
.. note::
186+
Each parenthesis group in a conditional will produce a GROUP. Thus, the original header_rewrite
187+
config will be more readable with ``if ...`` than `if (...)`.
188+
183189
Operators
184190
---------
185191

186-
Operators in ``header_rewrite`` mapt to HRW4U as a mix of assignments and function calls.
192+
Operators in ``header_rewrite`` map to HRW4U as a mix of assignments and function calls.
187193
The preference is the assignment style when appropriate.
188194

189195
============================= ================================= ================================================
@@ -220,6 +226,15 @@ set-debug set-debug() Enables ATS txn debug
220226
skip-remap skip-remap() Skip remap processing (open proxy)
221227
================= ============================ ================================
222228

229+
String concatenations
230+
---------------------
231+
232+
You can concatenate values using strings, condition values and variable expansions on the same line in
233+
operators using. For instance, `outbound.req.CustomHeader “Hello from {inbound.ip}:{inbound.port}”`. As
234+
a result, the set-redirect's `[QSA]` flag would be implemented as `set-redirect(302, "https://...?{inbound.url.query}")``.
235+
Note the presence of the `?` -- the url.query doesn't include it.
236+
237+
223238
Semantics
224239
=========
225240

@@ -246,7 +261,8 @@ A special section `VARS` is used to declare variables. There is no equivalent in
246261
`header_rewrite`, where you managed the variables manually.
247262

248263
.. note::
249-
The section name is always required in HRW4U, there are no implicit or default hooks.
264+
The section name is always required in HRW4U, there are no implicit or default hooks. There
265+
can be several if/else block per section block.
250266

251267
Groups
252268
------

tools/hrw4u/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build/
2+
dist/

tools/hrw4u/bootstrap.sh

100644100755
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,22 @@ set -e
2020

2121
VENV_NAME="hrw4u"
2222

23+
if ! which antlr; then
24+
echo "Make sure antlr is installed, e.g. brew install antlr"
25+
echo "Once its in your path, re-run this script."
26+
exit
27+
fi
28+
2329
eval "$(pyenv init --path)"
2430
eval "$(pyenv init -)"
2531
# eval "$(pyenv virtualenv-init -)"
2632

27-
echo "==> Creating virtualenv $VENV_NAME..."
28-
pyenv virtualenv "$VENV_NAME"
33+
if pyenv virtualenvs | grep hrw4u; then
34+
pyenv uninstall -f "$VENV_NAME"
35+
else
36+
echo "==> Creating virtualenv $VENV_NAME..."
37+
pyenv virtualenv "$VENV_NAME"
38+
fi
2939

3040
echo "==> Activating virtualenv..."
3141
pyenv activate "$VENV_NAME"

tools/hrw4u/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@
1717
antlr4-python3-runtime
1818
pytest
1919
pyinstaller
20+
build

0 commit comments

Comments
 (0)