Commit 97301b3a authored by rgaudin's avatar rgaudin
Browse files

Use the main ideascube catalog URL as test URL

- Testing URL is required to be working for Kiwix Hotspot to function
- Safer as previous URL (favicon) might be removed
- Kiwx Hotspot unusable anyway if this new file is not available
parent 8c61eff4
......@@ -112,7 +112,14 @@ class RequestedFile(object):
)
def stream(url, write_to=None, callback=None, block_size=1024, proxies=None):
def stream(
url,
write_to=None,
callback=None,
block_size=1024,
proxies=None,
only_first_block=False,
):
""" download an URL without blocking
- retries download on failure (with increasing wait delay)
......@@ -137,6 +144,10 @@ def stream(url, write_to=None, callback=None, block_size=1024, proxies=None):
)
total_size = int(req.headers.get("content-length", 0))
# adjust if we are only requesting first block
if only_first_block and total_size > block_size:
total_size = block_size
total_downloaded = 0
if write_to is not None:
fd = open(write_to, "wb")
......@@ -149,6 +160,10 @@ def stream(url, write_to=None, callback=None, block_size=1024, proxies=None):
if write_to:
fd.write(data)
# stop downloading/reading if we're just testing first block
if only_first_block:
break
if write_to:
fd.close()
else:
......@@ -198,7 +213,9 @@ def test_connection(proxies=None):
("HTTP", http_proxy_test_url),
("HTTPS", https_proxy_test_url),
):
size, fd = stream(url, proxies=proxies, callback=hook)
size, fd = stream(
url, proxies=proxies, callback=hook, only_first_block=True
)
except Exception:
return False, kind
else:
......
......@@ -26,8 +26,8 @@ ansiblecube_path = os.path.join(data_dir, "ansiblecube")
mirror = "http://download.kiwix.org"
sdcard_sizes = (8, 16, 32, 64, 128, 200, 256)
http_proxy_test_url = "http://download.kiwix.org/favicon.ico"
https_proxy_test_url = "https://download.kiwix.org/favicon.ico"
http_proxy_test_url = "http://download.kiwix.org/library/ideascube.yml"
https_proxy_test_url = "https://download.kiwix.org/library/ideascube.yml"
ideascube_languages = [
("am", u"አማርኛ"),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment