toymaker.git

commit a5ec5e4915787e6f726e09296699638ac20700e8

Author: Adam <git@apiote.xyz>

parse Accept header

 toymaker.sh | 21 +++++++++++++++------


diff --git a/toymaker.sh b/toymaker.sh
index e09267d33cff6de521d66757ac13a1ca7b30b5c8..dd70baf5d411e8b22970d625351424789c0162b6 100755
--- a/toymaker.sh
+++ b/toymaker.sh
@@ -50,23 +50,32 @@ 	mkfifo -m 0600 "/tmp/$name.fifo" && echo "/tmp/$name.fifo"
 }
 
 templateMessage() {
-	message=$1
+	message="$1"
 	templateName=$2
-	contentType=$3
-	case $contentType in
+	contentTypeHeader=$3
+	while [ -n "$contentTypeHeader" ]
+	do
+		contentType=$(echo "$contentTypeHeader" | cut -d ',' -f1)
+		contentTypeHeader=$(echo "$contentTypeHeader" | cut -d ',' -f2-)
+		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
 			;;
 		*)
-		return 1
-		;;
-	esac
+			continue
+			;;
+		esac
+	done
 	[ -f "templates/$templateName.$ext" ] || return 1
 	#shellcheck disable=SC1090
 	. "templates/$templateName.$ext"