summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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