Add code for resumable downloads from S3

This commit is contained in:
Joseph Schorr 2014-07-02 00:39:59 -04:00
parent d851feef6e
commit 0d89fd7f26
3 changed files with 17 additions and 2 deletions

View file

@ -101,6 +101,13 @@ def get_image_layer(namespace, repository, image_id, headers):
profile.debug('Looking up repo image')
repo_image = model.get_repo_image(namespace, repository, image_id)
# Add the Accept-Ranges header if the storage engine supports resumable
# downloads.
extra_headers = {}
if store.get_supports_resumable_downloads():
extra_headers['Accept-Ranges'] = 'bytes';
profile.debug('Looking up the layer path')
try:
path = store.image_layer_path(repo_image.storage.uuid)
@ -110,10 +117,12 @@ def get_image_layer(namespace, repository, image_id, headers):
if direct_download_url:
profile.debug('Returning direct download URL')
return redirect(direct_download_url)
resp = redirect(direct_download_url)
resp.headers = dict(headers, **extra_headers)
return resp
profile.debug('Streaming layer data')
return Response(store.stream_read(repo_image.storage.locations, path), headers=headers)
return Response(store.stream_read(repo_image.storage.locations, path), headers=dict(headers, **extra_headers))
except (IOError, AttributeError):
profile.debug('Image not found')
abort(404, 'Image %(image_id)s not found', issue='unknown-image',