diff --git a/src/dependencies.optional b/src/dependencies.optional index 37b45bb..62629e1 100644 --- a/src/dependencies.optional +++ b/src/dependencies.optional @@ -1,3 +1,4 @@ sha1sum sha256sum curl +iconv diff --git a/src/mime.sh b/src/mime.sh index f5b5a02..2661e63 100755 --- a/src/mime.sh +++ b/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 } diff --git a/src/response/200.sh b/src/response/200.sh index c6d717e..825092e 100755 --- a/src/response/200.sh +++ b/src/response/200.sh @@ -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