From: Lukas Schauer Date: Tue, 6 Feb 2018 22:08:16 +0000 (+0100) Subject: http_request: make http headers available on fd 4 X-Git-Tag: v0.6.0~16 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=a7b2af2b92baef48b0ee38ab37deeda58f1a94a1;p=thirdparty%2Fdehydrated.git http_request: make http headers available on fd 4 --- diff --git a/dehydrated b/dehydrated index 80db794..7357f6f 100755 --- a/dehydrated +++ b/dehydrated @@ -450,6 +450,7 @@ _openssl() { # Send http(s) request with specified method http_request() { tempcont="$(_mktemp)" + tempheaders="$(_mktemp)" if [[ -n "${IP_VERSION:-}" ]]; then ip_version="-${IP_VERSION}" @@ -458,12 +459,13 @@ http_request() { set +e if [[ "${1}" = "head" ]]; then statuscode="$(curl ${ip_version:-} ${CURL_OPTS} -s -w "%{http_code}" -o "${tempcont}" "${2}" -I)" + touch "${tempheaders}" curlret="${?}" elif [[ "${1}" = "get" ]]; then - statuscode="$(curl ${ip_version:-} ${CURL_OPTS} -L -s -w "%{http_code}" -o "${tempcont}" "${2}")" + statuscode="$(curl ${ip_version:-} ${CURL_OPTS} -L -s -w "%{http_code}" -o "${tempcont}" -D "${tempheaders}" "${2}")" curlret="${?}" elif [[ "${1}" = "post" ]]; then - statuscode="$(curl ${ip_version:-} ${CURL_OPTS} -s -w "%{http_code}" -o "${tempcont}" "${2}" -d "${3}")" + statuscode="$(curl ${ip_version:-} ${CURL_OPTS} -s -w "%{http_code}" -o "${tempcont}" "${2}" -D "${tempheaders}" -d "${3}")" curlret="${?}" else set -e @@ -485,6 +487,7 @@ http_request() { echo " + ERROR: An error occurred while sending ${1}-request to ${2} (Status ${statuscode})" >&2 echo >&2 echo "Details:" >&2 + cat "${tempheaders}" >&2 cat "${tempcont}" >&2 echo >&2 echo >&2 @@ -496,6 +499,7 @@ http_request() { fi rm -f "${tempcont}" + rm -f "${tempheaders}" # Wait for hook script to clean the challenge if used if [[ -n "${HOOK}" ]] && [[ "${HOOK_CHAIN}" != "yes" ]] && [[ -n "${challenge_token:+set}" ]]; then @@ -508,8 +512,12 @@ http_request() { fi fi + if { true >&4; } 2>/dev/null; then + cat "${tempheaders}" >&4 + fi cat "${tempcont}" rm -f "${tempcont}" + rm -f "${tempheaders}" } # Send signed request