@@ -210,7 +210,7 @@ def _request(self, method, url,
210
210
files = None , save = False , savedir = '' , timeout = None , cache = True ,
211
211
stream = False , auth = None , continuation = True , verify = True ,
212
212
allow_redirects = True ,
213
- json = None ):
213
+ json = None , return_response_on_save = False ):
214
214
"""
215
215
A generic HTTP request method, similar to `requests.Session.request`
216
216
but with added caching-related tools
@@ -249,14 +249,21 @@ def _request(self, method, url,
249
249
parameter will try to continue the download where it left off.
250
250
See `_download_file`.
251
251
stream : bool
252
+ return_response_on_save : bool
253
+ If ``save``, also return the server response. The default is to only
254
+ return the local file path.
252
255
253
256
Returns
254
257
-------
255
258
response : `requests.Response`
256
259
The response from the server if ``save`` is False
257
260
local_filepath : list
258
261
a list of strings containing the downloaded local paths if ``save``
259
- is True
262
+ is True and ``return_response_on_save`` is False.
263
+ (local_filepath, response) : tuple(list, `requests.Response`)
264
+ a tuple containing a list of strings containing the downloaded local paths,
265
+ and the server response object, if ``save`` is True and ``return_response_on_save``
266
+ is True.
260
267
"""
261
268
req_kwargs = dict (
262
269
params = params ,
@@ -274,11 +281,14 @@ def _request(self, method, url,
274
281
local_filename = local_filename .replace (':' , '_' )
275
282
local_filepath = os .path .join (savedir or self .cache_location or '.' , local_filename )
276
283
277
- self ._download_file (url , local_filepath , cache = cache ,
278
- continuation = continuation , method = method ,
279
- allow_redirects = allow_redirects ,
280
- auth = auth , ** req_kwargs )
281
- return local_filepath
284
+ response = self ._download_file (url , local_filepath , cache = cache ,
285
+ continuation = continuation , method = method ,
286
+ allow_redirects = allow_redirects ,
287
+ auth = auth , ** req_kwargs )
288
+ if return_response_on_save :
289
+ return local_filepath , response
290
+ else :
291
+ return local_filepath
282
292
else :
283
293
query = AstroQuery (method , url , ** req_kwargs )
284
294
if ((self .cache_location is None ) or (not self ._cache_active ) or (not cache )):
@@ -369,6 +379,7 @@ def _download_file(self, url, local_filepath, timeout=None, auth=None,
369
379
timeout = timeout , stream = True ,
370
380
auth = auth , ** kwargs )
371
381
response .raise_for_status ()
382
+ del self ._session .headers ['Range' ]
372
383
373
384
elif cache and os .path .exists (local_filepath ):
374
385
if length is not None :
0 commit comments