Retry launcher downloads when the response ends early.

This commit is contained in:
DeepDaddyTTV
2026-11-09 21:28:11 -05:00
committed by chrg6
parent f19ed09f1c
commit da303e830d
2 changed files with 32 additions and 5 deletions

View File

@@ -85,7 +85,8 @@ class Server:
self.send_response(status)
for k, v in headers.items():
self.send_header(k, v)
self.send_header('Content-Length', str(len(body)))
if 'Content-Length' not in headers:
self.send_header('Content-Length', str(len(body)))
self.end_headers()
self.wfile.write(body)
return
@@ -521,6 +522,22 @@ class NetTest(Tmp):
with self.assertRaises(ConnectionResetError): # every try failed: the last error goes up
net.get_bytes('https://example.invalid/down')
def test_early_eof_retries_metadata_and_resumes_file(self):
data = b'{"build":123}'
(self.tmp / 'asset').write_bytes(data)
cut = (200, {'Content-Length': str(len(data))}, data[:7])
routes = {'/asset': cut}
srv = Server(self.tmp, routes)
self.addCleanup(srv.close)
url = srv.url + 'asset'
with mock.patch.object(net.time, 'sleep', side_effect=lambda _: routes.clear()):
self.assertEqual(net.get_json(url), {'build': 123})
routes['/asset'] = cut
dest = self.tmp / 'download'
net.download(url, dest, sha256=sha(data), size=len(data))
self.assertEqual(dest.read_bytes(), data)
self.assertEqual([h.get('Range') for _, h in srv.hits], [None, None, None, 'bytes=7-'])
def test_download_resume_and_checks(self):
data = os.urandom(3 * net.CHUNK + 123)
(self.tmp / 'f.bin').write_bytes(data)