+ on-the-fly text conversion (UTF-8 -> anything)
parent
809633fe3b
commit
7d055ccab1
|
@ -1,3 +1,4 @@
|
|||
sha1sum
|
||||
sha256sum
|
||||
curl
|
||||
iconv
|
||||
|
|
12
src/mime.sh
12
src/mime.sh
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
[[ "${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"
|
||||
if [[ "$mimetype" == "text/"* && "${cfg[encoding]}" != '' ]]; then
|
||||
iconv "${r[uri]}" -f UTF-8 -t "${cfg[encoding]}"
|
||||
else
|
||||
cat "${r[uri]}"
|
||||
fi
|
||||
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue