@@ -72,12 +72,10 @@ def download_path(url):
72
72
73
73
return os .path .join (temp_path (), filename )
74
74
75
-
76
-
77
75
def _http_request (url , headers = None , time_out = 10 ):
78
- """Perform an HTTP request and return the response and content."""
79
- headers = headers or {}
80
-
76
+ """Perform an HTTP request and return the response object and content."""
77
+ if headers is None :
78
+ headers = {}
81
79
log (0 , 'Request URL: {url}' , url = url )
82
80
request = Request (url , headers = headers )
83
81
@@ -86,14 +84,14 @@ def _http_request(url, headers=None, time_out=10):
86
84
log (0 , 'Response code: {code}' , code = response .getcode ())
87
85
if 400 <= response .getcode () < 600 :
88
86
raise HTTPError (url , response .getcode (), f'HTTP { response .getcode ()} Error for url: { url } ' , response .headers , None )
89
- # Read the content inside the `with` block
90
87
content = response .read ()
88
+ # Return both response object and content
91
89
return response , content
92
90
except (HTTPError , URLError ) as err :
93
91
log (2 , 'Download failed with error {}' .format (err ))
94
92
if yesno_dialog (localize (30004 ), '{line1}\n {line2}' .format (line1 = localize (30063 ), line2 = localize (30065 ))): # Internet down, try again?
95
93
return _http_request (url , headers , time_out )
96
- return None
94
+ return None , None
97
95
98
96
def http_get (url ):
99
97
"""Perform an HTTP GET request and return content."""
@@ -131,7 +129,7 @@ def http_download(url, message=None, checksum=None, hash_alg='sha1', dl_size=Non
131
129
log (4 , 'Invalid hash algorithm specified: {}' .format (hash_alg ))
132
130
checksum = None
133
131
134
- req = _http_request (url )
132
+ req , _ = _http_request (url )
135
133
if req is None :
136
134
return None
137
135
@@ -166,7 +164,7 @@ def http_download(url, message=None, checksum=None, hash_alg='sha1', dl_size=Non
166
164
return False
167
165
168
166
headers = {'Range' : 'bytes={}-{}' .format (size , total_length )}
169
- req = _http_request (url , headers = headers )
167
+ req , _ = _http_request (url , headers = headers )
170
168
if req is None :
171
169
return None
172
170
continue
0 commit comments