]> git.feebdaed.xyz Git - 0xmirror/pi-hole.git/commitdiff
Revert "pihole api - use keepalive for curl queries"
authorAdam Warner <github@adamwarner.co.uk>
Sat, 26 Jul 2025 11:35:02 +0000 (12:35 +0100)
committerGitHub <noreply@github.com>
Sat, 26 Jul 2025 11:35:02 +0000 (12:35 +0100)
advanced/Scripts/api.sh

index 53dabebbe9ee552a63cee2c161ccc005788be983..7589d3ffda4519f13b6857b4584f70c3c9dd5e82 100755 (executable)
@@ -55,7 +55,7 @@ TestAPIAvailability() {
         API_URL="${API_URL#\"}"
 
         # Test if the API is available at this URL, include delimiter for ease in splitting payload
-        authResponse=$(curl --connect-timeout 2 -skS -H "Connection: keep-alive" -w ">>%{http_code}" "${API_URL}auth")
+        authResponse=$(curl --connect-timeout 2 -skS -w ">>%{http_code}" "${API_URL}auth")
 
         # authStatus is the response http_code, eg. 200, 401.
         # Shell parameter expansion, remove everything up to and including the >> delim
@@ -184,7 +184,7 @@ LoginAPI() {
 }
 
 Authentication() {
-    sessionResponse=$(curl --connect-timeout 2 -skS -H "Connection: keep-alive" -X POST "${API_URL}auth" --user-agent "Pi-hole cli" --data "{\"password\":\"${password}\", \"totp\":${totp:-null}}")
+    sessionResponse="$(curl --connect-timeout 2 -skS -X POST "${API_URL}auth" --user-agent "Pi-hole cli" --data "{\"password\":\"${password}\", \"totp\":${totp:-null}}" )"
 
     if [ -z "${sessionResponse}" ]; then
         echo "No response from FTL server. Please check connectivity"
@@ -219,7 +219,7 @@ LogoutAPI() {
     # SID is not null (successful Authentication only), delete the session
     if [ "${validSession}" = true ] && [ ! "${SID}" = null ]; then
         # Try to delete the session. Omit the output, but get the http status code
-        deleteResponse=$(curl -skS -o /dev/null -w "%{http_code}" -X DELETE "${API_URL}auth" -H "Accept: application/json" -H "sid: ${SID}" -H "Connection: keep-alive")
+        deleteResponse=$(curl -skS -o /dev/null -w "%{http_code}" -X DELETE "${API_URL}auth"  -H "Accept: application/json" -H "sid: ${SID}")
 
         case "${deleteResponse}" in
             "401") echo "Logout attempt without a valid session. Unauthorized!";;
@@ -233,7 +233,7 @@ LogoutAPI() {
 GetFTLData() {
   local data response status
   # get the data from querying the API as well as the http status code
-  response=$(curl -skS -w "%{http_code}" -X GET "${API_URL}$1" -H "Accept: application/json" -H "sid: ${SID}" -H "Connection: keep-alive")
+  response=$(curl -skS -w "%{http_code}" -X GET "${API_URL}$1" -H "Accept: application/json" -H "sid: ${SID}" )
 
   if [ "${2}" = "raw" ]; then
     # return the raw response
@@ -260,7 +260,7 @@ GetFTLData() {
 PostFTLData() {
   local data response status
   # send the data to the API
-  response=$(curl -skS -w "%{http_code}" -X POST "${API_URL}$1" --data-raw "$2" -H "Accept: application/json" -H "sid: ${SID}" -H "Connection: keep-alive")
+  response=$(curl -skS -w "%{http_code}" -X POST "${API_URL}$1" --data-raw "$2" -H "Accept: application/json" -H "sid: ${SID}" )
   # data is everything from response without the last 3 characters
   if [ "${3}" = "status" ]; then
     # Keep the status code appended if requested