From af46d3d455f7dc53322a486b2c0a5ad08c3d22bd Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Mon, 7 Jul 2014 16:21:27 -0400 Subject: [PATCH] Remove path from get_supports_resumeable_download --- endpoints/registry.py | 31 +++++++++++++------------------ storage/basestorage.py | 2 +- storage/s3.py | 2 +- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/endpoints/registry.py b/endpoints/registry.py index bd78e6055..cc2342fe4 100644 --- a/endpoints/registry.py +++ b/endpoints/registry.py @@ -100,27 +100,22 @@ def head_image_layer(namespace, repository, image_id, headers): 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) - - # Add the Accept-Ranges header if the storage engine supports resumeable - # downloads. - extra_headers = {} - - profile.debug('Looking up the layer path') - try: - path = store.image_layer_path(repo_image.storage.uuid) - - if store.get_supports_resumeable_downloads(repo_image.storage.locations, path): - profile.debug('Storage supports resumeable downloads') - extra_headers['Accept-Ranges'] = 'bytes'; - - resp = make_response('') - resp.headers.extend(extra_headers) - return resp - - except (IOError, AttributeError): + 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) diff --git a/storage/basestorage.py b/storage/basestorage.py index a6b2c581c..2d3727a5b 100644 --- a/storage/basestorage.py +++ b/storage/basestorage.py @@ -57,7 +57,7 @@ class BaseStorage(StoragePaths): def get_direct_download_url(self, path, expires_in=60): return None - def get_supports_resumeable_downloads(self, path): + def get_supports_resumeable_downloads(self): return False def get_content(self, path): diff --git a/storage/s3.py b/storage/s3.py index 1f9c30211..12c2373de 100644 --- a/storage/s3.py +++ b/storage/s3.py @@ -83,7 +83,7 @@ class S3Storage(BaseStorage): key.set_contents_from_string(content, encrypt_key=True) return path - def get_supports_resumeable_downloads(self, path): + def get_supports_resumeable_downloads(self): return True def get_direct_download_url(self, path, expires_in=60):