mirror of
https://github.com/pi-hole/pi-hole.git
synced 2025-07-28 08:04:11 +02:00
Use shell parameter expansion to split http_code and payload
Codespell editorconfig Signed-off-by: Dan Schaper <dan.schaper@pi-hole.net>
This commit is contained in:
parent
1bdbc26a07
commit
de31858950
@ -47,14 +47,15 @@ TestAPIAvailability() {
|
|||||||
API_URL="${API_URL%\"}"
|
API_URL="${API_URL%\"}"
|
||||||
API_URL="${API_URL#\"}"
|
API_URL="${API_URL#\"}"
|
||||||
|
|
||||||
# Test if the API is available at this URL
|
# 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")
|
authResponse=$(curl --connect-timeout 2 -skS -w ">>%{http_code}" "${API_URL}auth")
|
||||||
|
|
||||||
# authStatus are the last 3 characters
|
# authStatus is the response http_code, eg. 200, 401.
|
||||||
# not using ${authResponse#"${authResponse%???}"}" here because it's extremely slow on big responses
|
# Shell parameter expansion, remove everything up to and including the >> delim
|
||||||
authStatus=$(printf "%s" "${authResponse}" | tail -c 3)
|
authStatus=${authResponse#*>>}
|
||||||
# data is everything from response without the last 3 characters
|
# data is everything from response
|
||||||
authData=$(printf %s "${authResponse%???}")
|
# Shell parameter expansion, remove the >> delim and everything after
|
||||||
|
authData=${authResponse%>>*}
|
||||||
|
|
||||||
# Test if http status code was 200 (OK) or 401 (authentication required)
|
# Test if http status code was 200 (OK) or 401 (authentication required)
|
||||||
if [ "${authStatus}" = 200 ]; then
|
if [ "${authStatus}" = 200 ]; then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user