diff options
author | tv <tv@krebsco.de> | 2017-03-16 19:16:11 +0100 |
---|---|---|
committer | tv <tv@krebsco.de> | 2017-03-16 19:32:36 +0100 |
commit | 2b40d680fa9aabeabb6746be0caa56935d4ecb7f (patch) | |
tree | 9f03c75dbbc26366d1337932248c261dcb511cc1 | |
parent | d7b9e60202642254132059bc5f1d88e9a73770fc (diff) |
support short URIs
-rwxr-xr-x | htgen | 19 |
1 files changed, 17 insertions, 2 deletions
@@ -93,12 +93,23 @@ unset k v echo >&2 ## }}} +find_item() { + if test ${#1} -ge 7; then + set -- "$(find "$STATEDIR/items" -type f -mindepth 1 -maxdepth 1 \ + -regex "$STATEDIR/items/$1[0-9A-Za-z]*$")" + if test $(printf '%s' "$1" | wc -l) = 1; then + echo "$1" + return 0 + fi + fi + return 1 +} + # run server: STATEDIR=/tmp/htgen-state HTGEN_PORT=1080 ./htgen --serve # paste: echo lol | curl http://localhost:1080 -d @- case "$Method $Request_URI" in "GET /"[0-9a-z]*) - item=$STATEDIR/items$Request_URI - if test -e $item; then + if item=$(find_item ${Request_URI:1}); then printf 'HTTP/1.1 200 OK\r\n' printf 'Content-Type: %s\r\n' "$(file -ib $item)" printf 'Server: %s\r\n' "$Server" @@ -129,6 +140,10 @@ case "$Method $Request_URI" in cp -v $content $item >&2 fi + if item=$(find_item ${base32:0:7}); then + ref=$(echo "$ref"; echo "http://$req_host/${base32:0:7}") + fi + printf 'HTTP/1.1 200 OK\r\n' printf 'Content-Type: text/plain; charset=UTF-8\r\n' printf 'Server: %s\r\n' "$Server" |