Add code for resumable downloads from S3
This commit is contained in:
parent
d851feef6e
commit
0d89fd7f26
3 changed files with 17 additions and 2 deletions
|
@ -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',
|
||||
|
|
|
@ -57,6 +57,9 @@ class BaseStorage(StoragePaths):
|
|||
def get_direct_download_url(self, path, expires_in=60):
|
||||
return None
|
||||
|
||||
def get_supports_resumable_downloads(self):
|
||||
return False
|
||||
|
||||
def get_content(self, path):
|
||||
raise NotImplementedError
|
||||
|
||||
|
|
|
@ -83,6 +83,9 @@ class S3Storage(BaseStorage):
|
|||
key.set_contents_from_string(content, encrypt_key=True)
|
||||
return path
|
||||
|
||||
def get_supports_resumable_downloads(self):
|
||||
return True
|
||||
|
||||
def get_direct_download_url(self, path, expires_in=60):
|
||||
self._initialize_s3()
|
||||
path = self._init_path(path)
|
||||
|
|
Reference in a new issue