diff options
author | tv <tv@krebsco.de> | 2020-12-28 00:17:55 +0100 |
---|---|---|
committer | tv <tv@krebsco.de> | 2020-12-28 00:17:55 +0100 |
commit | d948340fea80c9d9588128fbf36e94a686a2784b (patch) | |
tree | 098000b5eb5b1b0f75b8646f01c2b9166d7e29f0 | |
parent | f802b4637d4ad6f1fd0e55807fd75de348d8d51f (diff) |
parse request line using jq instead of sed
-rwxr-xr-x | htgen | 33 |
1 files changed, 16 insertions, 17 deletions
@@ -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 |