Author: Adam <git@apiote.xyz>
fix wrong content type in responses
toymaker.sh | 20 +++++++++++---------
diff --git a/toymaker.sh b/toymaker.sh index 5aeba871d28739ca0d844a73efa0352200676a05..085f46c9947b7565d45e5299bac7e9b98a299754 100755 --- a/toymaker.sh +++ b/toymaker.sh @@ -61,24 +61,24 @@ contentType=$(echo "$contentType" | cut -d ';' -f1) case $contentType in text/plain) ext='txt' - break ;; text/html|\*|\*/\*|'') ext='html' - break ;; image/\*|image/svg) ext='svg' - break ;; *) continue ;; esac + [ -f "templates/$templateName.$ext" ] && break + ext='' done - [ -f "templates/$templateName.$ext" ] || return 1 + [ -n "$ext" ] || return 1 #shellcheck disable=SC1090 . "templates/$templateName.$ext" + printf '%s\n' "$contentType" template "$message" } @@ -200,7 +200,7 @@ if [ "$toy" = '' ] then if page=$(templateMessage "$(list_toys)" 'toys' 'text/html') then - respond200 "$page" + respond200 "$(echo "$page" | tail -n+2)" else respond406 "$accept" fi @@ -213,7 +213,7 @@ then respond404 "$path" elif page=$(templateMessage "$toy;$content" 'toy' 'text/html') then - respond200 "$page" + respond200 "$(echo "$page" | tail -n+2)" else respond406 "$accept" fi @@ -233,13 +233,15 @@ status=$(echo "$r" | head -n1 | cut -d ';' -f1) if [ "$status" = 'n' ] then respond404 "$path" - elif page=$(templateMessage "$toy;$item;$r" 'item' "$accept") # add artifacts to message + elif page=$(templateMessage "$toy;$item;$r" 'item' "$accept") # todo add artifacts to message then + body=$(echo "$page" | tail -n+2) + contentType=$(echo "$page" | head -n1) if [ "$status" = 'r' ] then - respond202 "$toy" "$item" "$page" "$accept" + respond202 "$toy" "$item" "$body" "$contentType" else - respond200 "$page" "$accept" + respond200 "$body" "$contentType" fi else respond406 "$accept"