From de31858950a61a5eb90a0a1c59635b32c1dfcdc1 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 12 May 2025 12:01:34 -0700 Subject: [PATCH] Use shell parameter expansion to split http_code and payload Codespell editorconfig Signed-off-by: Dan Schaper --- advanced/Scripts/api.sh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/advanced/Scripts/api.sh b/advanced/Scripts/api.sh index 97192108..20ebef5c 100755 --- a/advanced/Scripts/api.sh +++ b/advanced/Scripts/api.sh @@ -47,14 +47,15 @@ TestAPIAvailability() { API_URL="${API_URL%\"}" API_URL="${API_URL#\"}" - # Test if the API is available at this URL - authResponse=$(curl --connect-timeout 2 -skS -w "%{http_code}" "${API_URL}auth") + # Test if the API is available at this URL, include delimiter for ease in splitting payload + authResponse=$(curl --connect-timeout 2 -skS -w ">>%{http_code}" "${API_URL}auth") - # authStatus are the last 3 characters - # not using ${authResponse#"${authResponse%???}"}" here because it's extremely slow on big responses - authStatus=$(printf "%s" "${authResponse}" | tail -c 3) - # data is everything from response without the last 3 characters - authData=$(printf %s "${authResponse%???}") + # authStatus is the response http_code, eg. 200, 401. + # Shell parameter expansion, remove everything up to and including the >> delim + authStatus=${authResponse#*>>} + # data is everything from response + # Shell parameter expansion, remove the >> delim and everything after + authData=${authResponse%>>*} # Test if http status code was 200 (OK) or 401 (authentication required) if [ "${authStatus}" = 200 ]; then