+ on-the-fly text conversion (UTF-8 -> anything)

merge-requests/2/head
Dominika Liberda 2021-02-02 17:11:18 +01:00
parent 809633fe3b
commit 7d055ccab1
3 changed files with 18 additions and 11 deletions

View File

@ -1,3 +1,4 @@
sha1sum
sha256sum
curl
iconv

View File

@ -16,16 +16,14 @@ function get_mime() {
local file="$@"
local mime="$(file --mime-type -b "$file")"
if [[ $file == *".htm" || $file == *".html" ]]; then
content_type="text/html"
return 0
mimetype="text/html"
elif [[ $file == *".shs" || $file == *".py" || $file == *".php" ]]; then
content_type=""
return 0
mimetype=""
elif [[ $file == *".css" ]]; then
content_type="text/css"
mimetype="text/css"
elif [[ $mime == "text/"* ]]; then
content_type="text/plain"
mimetype="text/plain"
else
content_type="$mime"
mimetype="$mime"
fi
}

View File

@ -1,7 +1,7 @@
printf "HTTP/1.0 200 OK
${cfg[extra_headers]}\r\n"
get_mime "${r[uri]}"
[[ $content_type != '' ]] && printf "content-type: $content_type\r\n"
[[ "$mimetype" != '' ]] && printf "content-type: $mimetype\r\n"
if [[ ${cfg[php_enabled]} == true && ${r[uri]} =~ ".php" ]]; then
temp=$(mktemp)
@ -20,12 +20,20 @@ elif [[ ${cfg[python_enabled]} == true && ${r[uri]} =~ ".py" ]]; then
elif [[ ${r[uri]} =~ \.${cfg[extension]}$ ]]; then
temp=$(mktemp)
source "${r[uri]}" > $temp
[[ ${r[headers]} != '' ]] && printf "${r[headers]}\r\n\r\n" || printf "\r\n"
cat $temp
[[ "${r[headers]}" != '' ]] && printf "${r[headers]}\r\n\r\n" || printf "\r\n"
if [[ "${cfg[encoding]}" != '' ]]; then
iconv $temp -f UTF-8 -t "${cfg[encoding]}"
else
cat $temp
fi
rm $temp
else
printf "\r\n"
cat "${r[uri]}"
if [[ "$mimetype" == "text/"* && "${cfg[encoding]}" != '' ]]; then
iconv "${r[uri]}" -f UTF-8 -t "${cfg[encoding]}"
else
cat "${r[uri]}"
fi
fi