Optimize server startup speed, client update caching, and HTTP 304 conditional downloads
CI Test Suite / Run Component Tests & Pipeline Verification (push) Failing after 1m28s

This commit is contained in:
2026-10-02 22:43:18 +02:00
parent fe9d43cab6
commit 9ebfadbe89
5 changed files with 213 additions and 45 deletions
+37 -11
View File
@@ -76,22 +76,48 @@ class ClientUpdater:
def download_package(self, download_path_rel: str, expected_sha256: str, target_temp: str, timeout: int = 30) -> bool:
"""
Downloads the client binary package from the server and validates its SHA-256 checksum.
Uses local binary hash checking and ETag conditional headers to avoid redundant downloads.
"""
# 1. If running binary already matches target SHA-256, skip downloading
target_exec = sys.executable
if expected_sha256 and os.path.exists(target_exec):
try:
local_sha = self.calculate_sha256(target_exec)
if local_sha and local_sha == expected_sha256.lower():
print(f"[*] Local binary already matches target checksum ({local_sha[:12]}...). Skipping redundant download.")
return True
except Exception:
pass
base_url = self.get_server_base_url()
download_url = f"{base_url.rstrip('/')}/{download_path_rel.lstrip('/')}"
print(f"[*] Downloading client update package from {download_url}...")
req = urllib.request.Request(
download_url,
headers={"User-Agent": f"LOGAR-Client/{self.current_version} ({self.os_type})"}
)
with urllib.request.urlopen(req, timeout=timeout) as resp:
if resp.status != 200:
print(f"[!] Server returned HTTP {resp.status} during update download.")
return False
with open(target_temp, "wb") as f:
while chunk := resp.read(65536):
f.write(chunk)
headers = {"User-Agent": f"LOGAR-Client/{self.current_version} ({self.os_type})"}
if expected_sha256:
headers["If-None-Match"] = f'"{expected_sha256}"'
req = urllib.request.Request(download_url, headers=headers)
try:
with urllib.request.urlopen(req, timeout=timeout) as resp:
if resp.status == 304:
print("[+] Server returned 304 Not Modified. Local binary package is current.")
return True
if resp.status != 200:
print(f"[!] Server returned HTTP {resp.status} during update download.")
return False
with open(target_temp, "wb") as f:
while chunk := resp.read(65536):
f.write(chunk)
except urllib.error.HTTPError as e:
if e.code == 304:
print("[+] Server returned 304 Not Modified. Local binary package is current.")
return True
print(f"[!] HTTP error during update download: {e}")
return False
except Exception as e:
print(f"[!] Error downloading update package: {e}")
return False
# Verify SHA-256
actual_sha256 = self.calculate_sha256(target_temp)