1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
From: Didier Raboud <odyx@debian.org>
Date: Thu, 19 Sep 2019 08:47:34 +0200
Subject: =?utf-8?q?Accelerate_HTTP=C2=A0check_by_doing_a_HEAD=2C_not_a_GET?=
---
base/utils.py | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/base/utils.py b/base/utils.py
index c9daa62..bfe985c 100644
--- a/base/utils.py
+++ b/base/utils.py
@@ -2249,12 +2249,14 @@ def check_library( so_file_path):
return ret_val
-def download_via_wget(target):
+def download_via_wget(target, head=False):
status = -1
wget = which("wget")
if target and wget:
wget = os.path.join(wget, "wget")
cmd = "%s --cache=off --tries=3 --timeout=60 --output-document=- %s" % (wget, target)
+ if head:
+ cmd += " --spider -S"
log.debug(cmd)
status, output = run(cmd)
log.debug("wget returned: %d" % status)
@@ -2262,12 +2264,14 @@ def download_via_wget(target):
log.debug("wget not found")
return status
-def download_via_curl(target):
+def download_via_curl(target, head=False):
status = -1
curl = which("curl")
if target and curl:
curl = os.path.join(curl, "curl")
cmd = "%s --output - --connect-timeout 5 --max-time 10 %s" % (curl, target)
+ if head:
+ cmd += " --head"
log.debug(cmd)
status, output = run(cmd)
log.debug("curl returned: %d" % status)
@@ -2289,9 +2293,9 @@ def check_network_via_ping(target):
return status
def check_network_connection(url=HTTP_CHECK_TARGET, ping_server=PING_CHECK_TARGET):
- status = download_via_wget(url)
+ status = download_via_wget(url, head=True)
if (status != 0):
- status = download_via_curl(url)
+ status = download_via_curl(url, head=True)
if (status != 0):
status = check_network_via_ping(ping_server)
return (status == 0)
|