Compare commits

...

4 Commits

Author SHA1 Message Date
RD WebDesign
ac78066657 Fix the github suggestion mess
Some checks are pending
CodeQL / Analyze (pull_request) Waiting to run
Test Supported Distributions / smoke-tests (pull_request) Waiting to run
Test Supported Distributions / distro-test (alpine_3_21) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (alpine_3_22) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (centos_10) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (centos_9) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (debian_11) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (debian_12) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (debian_13) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (fedora_40) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (fedora_41) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (fedora_42) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (ubuntu_20) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (ubuntu_22) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (ubuntu_24) (pull_request) Blocked by required conditions
Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
2025-10-19 16:14:55 -03:00
RD WebDesign
f4a395cb06 Apply suggestion from @MichaIng
Do not handle HTTP code "000" separately.
Use curl error messages for every error, including unknown/unexpected HTTP codes or non-HTTP errors.

Co-authored-by: MichaIng <micha@dietpi.com>
Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
2025-10-19 14:48:54 -03:00
RD WebDesign
0cfc02cbab Apply suggestion from @MichaIng
Remove the STDERR mute from curl command.

The `-s` flag already mutes all curl errors, so STDERR would only contain something if curl itself (or a shared library) is damaged/missing.

Co-authored-by: MichaIng <micha@dietpi.com>
Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
2025-10-19 14:41:39 -03:00
RD WebDesign
4e191da1a0 Improve curl error message including exit code and error message
This commit replaces the 3 digits http_code returned by curl with the json
output. This output contains all returned values, including http_code,
exitcode and errormsg.

Using json format, the old http_error "000" string is formated as a number "0".

Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
2025-10-17 22:37:45 -03:00

View File

@@ -611,7 +611,7 @@ compareLists() {
# Download specified URL and perform checks on HTTP status and file content
gravity_DownloadBlocklistFromUrl() {
local url="${1}" adlistID="${2}" saveLocation="${3}" compression="${4}" gravity_type="${5}" domain="${6}"
local listCurlBuffer str httpCode success="" ip customUpstreamResolver=""
local listCurlBuffer str curlJson httpCode curlErrorMsg="" curlExitCode="" success="" ip customUpstreamResolver=""
local file_path permissions ip_addr port blocked=false download=true
# modifiedOptions is an array to store all the options used to check if the adlist has been changed upstream
local modifiedOptions=()
@@ -755,9 +755,14 @@ gravity_DownloadBlocklistFromUrl() {
fi
if [[ "${download}" == true ]]; then
httpCode=$(curl --connect-timeout ${curl_connect_timeout} -s -L ${compression:+${compression}} ${customUpstreamResolver:+${customUpstreamResolver}} "${modifiedOptions[@]}" -w "%{http_code}" "${url}" -o "${listCurlBuffer}" 2>/dev/null)
curlJson=$(curl --connect-timeout ${curl_connect_timeout} -s -L ${compression:+${compression}} ${customUpstreamResolver:+${customUpstreamResolver}} "${modifiedOptions[@]}" -w "%{json}" "${url}" -o "${listCurlBuffer}")
fi
# Retrieve the HTTP code, exit code and error message returned by curl command
httpCode=$(echo "${curlJson}" | jq '.http_code')
curlErrorMsg=$(echo "${curlJson}" | jq '.errormsg')
curlExitCode=$(echo "${curlJson}" | jq '.exitcode')
case $url in
# Did we "download" a local file?
"file"*)
@@ -780,7 +785,6 @@ gravity_DownloadBlocklistFromUrl() {
echo -e "${OVER} ${TICK} ${str} No changes detected"
success=true
;;
"000") echo -e "${OVER} ${CROSS} ${str} Connection Refused" ;;
"403") echo -e "${OVER} ${CROSS} ${str} Forbidden" ;;
"404") echo -e "${OVER} ${CROSS} ${str} Not found" ;;
"408") echo -e "${OVER} ${CROSS} ${str} Time-out" ;;
@@ -789,7 +793,7 @@ gravity_DownloadBlocklistFromUrl() {
"504") echo -e "${OVER} ${CROSS} ${str} Connection Timed Out (Gateway)" ;;
"521") echo -e "${OVER} ${CROSS} ${str} Web Server Is Down (Cloudflare)" ;;
"522") echo -e "${OVER} ${CROSS} ${str} Connection Timed Out (Cloudflare)" ;;
*) echo -e "${OVER} ${CROSS} ${str} ${url} (${httpCode})" ;;
*) echo -e "${OVER} ${CROSS} ${str} Failure (exit_code=${COL_RED}${curlExitCode}${COL_NC} Msg: ${COL_CYAN}${curlErrorMsg}${COL_NC})" ;;
esac
;;
esac