diff options
-rwxr-xr-x | htgen | 43 |
1 files changed, 23 insertions, 20 deletions
@@ -66,26 +66,29 @@ cat>&2<<EOF EOF ## }}} ## Parse HTTP-Headers. {{{ -HTTP_Headers="`sed -rn 's/
$//;/^$/q;p'`" - -## debug -echo "$HTTP_Headers" | sed -r 's/.*/[1;35m^[;35m&[1;35m$[m/' >&2 - -## Parse HTTP_Headers into Variables. -eval "$( -echo "$HTTP_Headers" | sed -r ' - ## TODO concatenate lines - /^[^:]+-[^:]+:/s/^([a-zA-Z-]+):[[:space:]]*([^'\'']*)*$/\ - x=`echo \1 | tr - _`; \ - echo $x=\\'\'''\''\2'\''\\'\''\\;;\ - echo HTTP_Header_Variables=\\\${HTTP_Header_Variables+\\\$HTTP_Header_Variables:}$x\\;;\ - /;t - s/^([a-zA-Z]+):[[:space:]]*([^'\'']*)*$/\ - echo \1=\\'\'''\''\2'\''\\'\''\\;;\ - echo HTTP_Header_Variables=\\\${HTTP_Header_Variables+\\\$HTTP_Header_Variables:}\1\\;;\ - /;t - s/^.*/# &/ - '| sh)" >&2 +# TODO support https://tools.ietf.org/html/rfc7230#section-3.2.4, obs-fold? +# TODO allow headers to appear multiple times +k= +v= +while read -r line; do + line=${line%
} + case $line in + '') + break + ;; + [A-Za-z][0-9A-Za-z-]*:*) + k=${line%%:*} + k=${k//-/_} + k=${k,,} + k=req_$k + v=${line#*: } + v=${v## } + printf '[35m%s=[1m%s[m\n' "$k" "$v" >&2 + export "$k=$v" + ;; + esac +done +unset k v echo >&2 ## }}} |