mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-10-02 09:10:11 +02:00
add timeout to net.http_get() and index.download_repo_index()
The requests docs recommend this: http://docs.python-requests.org/en/master/user/quickstart/#timeouts And mirror-monitor was hanging forever on a bad mirror.
This commit is contained in:
parent
9c900ed63c
commit
a2aef721d8
@ -686,7 +686,7 @@ def get_mirror_service_urls(url):
|
||||
return urls
|
||||
|
||||
|
||||
def download_repo_index(url_str, etag=None, verify_fingerprint=True):
|
||||
def download_repo_index(url_str, etag=None, verify_fingerprint=True, timeout=600):
|
||||
"""Downloads and verifies index file, then returns its data.
|
||||
|
||||
Downloads the repository index from the given :param url_str and
|
||||
@ -710,7 +710,7 @@ def download_repo_index(url_str, etag=None, verify_fingerprint=True):
|
||||
fingerprint = query['fingerprint'][0]
|
||||
|
||||
url = urllib.parse.SplitResult(url.scheme, url.netloc, url.path + '/index-v1.jar', '', '')
|
||||
download, new_etag = net.http_get(url.geturl(), etag)
|
||||
download, new_etag = net.http_get(url.geturl(), etag, timeout)
|
||||
|
||||
if download is None:
|
||||
return None, new_etag
|
||||
|
@ -36,7 +36,7 @@ def download_file(url, local_filename=None, dldir='tmp'):
|
||||
return local_filename
|
||||
|
||||
|
||||
def http_get(url, etag=None):
|
||||
def http_get(url, etag=None, timeout=600):
|
||||
"""
|
||||
Downloads the content from the given URL by making a GET request.
|
||||
|
||||
@ -52,12 +52,12 @@ def http_get(url, etag=None):
|
||||
# TODO disable TLS Session IDs and TLS Session Tickets
|
||||
# (plain text cookie visible to anyone who can see the network traffic)
|
||||
if etag:
|
||||
r = requests.head(url, headers=headers)
|
||||
r = requests.head(url, headers=headers, timeout=timeout)
|
||||
r.raise_for_status()
|
||||
if 'ETag' in r.headers and etag == r.headers['ETag']:
|
||||
return None, etag
|
||||
|
||||
r = requests.get(url, headers=headers)
|
||||
r = requests.get(url, headers=headers, timeout=timeout)
|
||||
r.raise_for_status()
|
||||
|
||||
new_etag = None
|
||||
|
Loading…
Reference in New Issue
Block a user