summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2020-12-28 00:17:55 +0100
committertv <tv@krebsco.de>2020-12-28 00:17:55 +0100
commitd948340fea80c9d9588128fbf36e94a686a2784b (patch)
tree098000b5eb5b1b0f75b8646f01c2b9166d7e29f0
parentf802b4637d4ad6f1fd0e55807fd75de348d8d51f (diff)
parse request line using jq instead of sed
-rwxr-xr-xhtgen33
1 files changed, 16 insertions, 17 deletions
diff --git a/htgen b/htgen
index b5519dd..20ad13c 100755
--- a/htgen
+++ b/htgen
@@ -61,23 +61,22 @@ EOF
fi
## }}}
## Parse Request-Line. {{{
-read Request_Line
-eval "$(echo "$Request_Line" | sed -rn '
- s^([a-zA-Z]+) ([a-zA-Z0-9=?&+*/._-]+) HTTP/([0-9]+\.[0-9]+)\r$\
- Request_Line="&"\
- Method="\1"\
- Request_URI="\2"\
- HTTP_Version="\3"\
- p;t;i\
- Request_Line= # invalid request
-')"
-#echo "Request-Line: $Request_Line" >&2
-# cat>&2<<EOF
-# Request_Line='$Request_Line'
-# Method='$Method'
-# Request_URI='$Request_URI'
-# HTTP_Version='$HTTP_Version'
-# EOF
+eval "$(
+ read -r Request_Line
+ jq --arg Request_Line "$Request_Line" -nRr '
+ $Request_Line |
+ sub("\\r?$";"") |
+ match(
+ "^(?<Method>[A-Za-z]+)" +
+ " (?<Request_URI>[A-Za-z0-9%&+*./=?@_-]+)" +
+ " HTTP/(?<HTTP_Version>[0-9]+\\.[0-9]+)" +
+ "$"
+ )
+ .captures |
+ map("\(.name)=\(@sh "\(.string)")") |
+ join("\n")
+ '
+)"
## debug
if test "$HTGEN_VERBOSE" = true; then