Author: Adam <git@apiote.xyz>
template simple messages
templates/message.html | 18 ++++++++++++++++++ toymaker.sh | 10 +++-------
diff --git a/templates/message.html b/templates/message.html new file mode 100644 index 0000000000000000000000000000000000000000..f27f9e56d37d4aa4eac53e4bd5a73db290c0c97b --- /dev/null +++ b/templates/message.html @@ -0,0 +1,18 @@ +#!/bin/sh + +template() { + message=$1 + cat <<EOF +<!DOCTYPE html> +<html> + <head> + <title>item</title> + </head> + <body> +EOF + printf '\t\t<p>%s</p>\n' "$message" + cat <<EOF + </body> +</html> +EOF +} diff --git a/toymaker.sh b/toymaker.sh index 085f46c9947b7565d45e5299bac7e9b98a299754..bf8db9a1a0c8f9577175e39eb0b98a99cfd7f7c0 100755 --- a/toymaker.sh +++ b/toymaker.sh @@ -135,31 +135,27 @@ } respond404() { path=$1 - # todo html - message="$path not found" + message=$(templateMessage "$path not found" 'message' 'text/html' | tail -n+2) printf "HTTP/1.1 404 Not Found\r\nContent-Length: %s\r\n\r\n%s\r\n" "${#message}" "$message" > "$fifo1" printf "404 -" } respond405() { method=$1 - # todo html - message="$method unsupported" + message=$(templateMessage "$method unsupported" 'message' 'text/html' | tail -n+2) printf "HTTP/1.1 405 Method Not Allowed\r\nContent-Length: %s\r\n\r\n%s\r\n" "${#message}" "$message" > "$fifo1" printf "405 -" } respond406() { contentType=$1 - # todo html message="$contentType unsupported" printf "HTTP/1.1 406 Not Acceptable\r\nContent-Length: %s\r\n\r\n%s\r\n" "${#message}" "$message" > "$fifo1" printf "406 -" } respond500() { - # todo html - message="Server error: $1" + message=$(templateMessage "Server error: $1" 'message' 'text/html' | tail -n+2) printf "HTTP/1.1 500 Internal Server Error\r\nContent-Length: %s\r\n\r\n%s\r\n" "${#message}" "$message" > "$fifo1" printf "500 -" }