Merge remote-tracking branch 'origin/resume'
This commit is contained in:
commit
f40b7dbc54
4 changed files with 47 additions and 2 deletions
|
@ -88,6 +88,38 @@ def set_cache_headers(f):
|
|||
return wrapper
|
||||
|
||||
|
||||
@registry.route('/images/<image_id>/layer', methods=['HEAD'])
|
||||
@process_auth
|
||||
@extract_namespace_repo_from_session
|
||||
@require_completion
|
||||
@set_cache_headers
|
||||
def head_image_layer(namespace, repository, image_id, headers):
|
||||
permission = ReadRepositoryPermission(namespace, repository)
|
||||
|
||||
profile.debug('Checking repo permissions')
|
||||
if permission.can() or model.repository_is_public(namespace, repository):
|
||||
profile.debug('Looking up repo image')
|
||||
repo_image = model.get_repo_image(namespace, repository, image_id)
|
||||
if not repo_image:
|
||||
profile.debug('Image not found')
|
||||
abort(404, 'Image %(image_id)s not found', issue='unknown-image',
|
||||
image_id=image_id)
|
||||
|
||||
extra_headers = {}
|
||||
|
||||
# Add the Accept-Ranges header if the storage engine supports resumeable
|
||||
# downloads.
|
||||
if store.get_supports_resumeable_downloads(repo_image.storage.locations):
|
||||
profile.debug('Storage supports resumeable downloads')
|
||||
extra_headers['Accept-Ranges'] = 'bytes';
|
||||
|
||||
resp = make_response('')
|
||||
resp.headers.extend(extra_headers)
|
||||
return resp
|
||||
|
||||
abort(403)
|
||||
|
||||
|
||||
@registry.route('/images/<image_id>/layer', methods=['GET'])
|
||||
@process_auth
|
||||
@extract_namespace_repo_from_session
|
||||
|
@ -110,10 +142,11 @@ 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)
|
||||
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',
|
||||
|
@ -374,6 +407,11 @@ def put_image_json(namespace, repository, image_id):
|
|||
|
||||
profile.debug('Looking up repo image')
|
||||
repo_image = model.get_repo_image(namespace, repository, image_id)
|
||||
if not repo_image:
|
||||
profile.debug('Image not found')
|
||||
abort(404, 'Image %(image_id)s not found', issue='unknown-image',
|
||||
image_id=image_id)
|
||||
|
||||
uuid = repo_image.storage.uuid
|
||||
|
||||
if image_id != data['id']:
|
||||
|
|
Reference in a new issue