From 5be51165e279afe59cf4d7ea0a59d4f4d8570b23 Mon Sep 17 00:00:00 2001 From: Dominika Date: Sun, 19 Dec 2021 03:36:00 +0100 Subject: [PATCH] * now 302s properly (WiP?) --- src/response/200.sh | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/response/200.sh b/src/response/200.sh index 864c6e6..02fc1cf 100755 --- a/src/response/200.sh +++ b/src/response/200.sh @@ -1,14 +1,21 @@ -if [[ "${cfg[unbuffered]}" != true ]]; then - printf "HTTP/1.0 200 OK -${cfg[extra_headers]}\r\n" -else - echo "uh oh - we're running unbuffered" > /dev/stderr -fi - -if [[ ${r[status]} == 200 ]]; then - get_mime "${r[uri]}" - [[ "$mimetype" != '' ]] && printf "content-type: $mimetype\r\n" -fi +function __headers() { + if [[ "${cfg[unbuffered]}" != true ]]; then + if [[ "${r[headers]}" != *'Location'* ]]; then + printf "HTTP/1.0 200 OK\r\n" + else + printf "HTTP/1.0 302 aaaaa\r\n" + fi + [[ "${r[headers]}" != '' ]] && printf "${r[headers]}" + printf "${cfg[extra_headers]}\r\n\r\n" + else + echo "uh oh - we're running unbuffered" > /dev/stderr + fi + + if [[ ${r[status]} == 200 ]]; then + get_mime "${r[uri]}" + [[ "$mimetype" != '' ]] && printf "content-type: $mimetype\r\n" + fi +} if [[ ${r[status]} == 212 ]]; then if [[ "${cfg[unbuffered]}" == true ]]; then @@ -16,7 +23,7 @@ if [[ ${r[status]} == 212 ]]; then else temp=$(mktemp) source "${r[view]}" > $temp - [[ "${r[headers]}" != '' ]] && printf "${r[headers]}\r\n" || printf "\r\n" + __headers cat $temp rm $temp fi @@ -24,21 +31,21 @@ if [[ ${r[status]} == 212 ]]; then elif [[ "${cfg[php_enabled]}" == true && "${r[uri]}" =~ ".php" ]]; then temp=$(mktemp) php "${r[uri]}" "$(get_dump)" "$(post_dump)" > $temp - [[ "${r[headers]}" != '' ]] && printf "${r[headers]}\r\n" || printf "\r\n" + __headers cat $temp rm $temp elif [[ "${cfg[python_enabled]}" == true && "${r[uri]}" =~ ".py" ]]; then temp=$(mktemp) python "${r[uri]}" "$(get_dump)" "$(post_dump)" > $temp - [[ "${r[headers]}" != '' ]] && printf "${r[headers]}\r\n" || printf "\r\n" + __headers cat $temp rm $temp elif [[ "${r[uri]}" =~ \.${cfg[extension]}$ ]]; then temp=$(mktemp) source "${r[uri]}" > $temp - [[ "${r[headers]}" != '' ]] && printf "${r[headers]}\r\n" || printf "\r\n" + __headers if [[ "${cfg[encoding]}" != '' ]]; then iconv $temp -f UTF-8 -t "${cfg[encoding]}" else