v2/blob: s/make_response/Response()

This commit is contained in:
Jimmy Zelinskie 2016-08-09 12:28:00 -04:00
parent 35579093ca
commit 16b451437f
2 changed files with 65 additions and 61 deletions

View file

@ -1,7 +1,7 @@
import logging
import re
from flask import make_response, url_for, request, redirect, Response, abort as flask_abort
from flask import url_for, request, redirect, Response, abort as flask_abort
import resumablehashlib
@ -57,9 +57,7 @@ def check_blob_exists(namespace_name, repo_name, digest):
headers['Accept-Ranges'] = 'bytes'
# Write the response to the Docker client.
response = make_response('')
response.headers.extend(headers)
return response
return Response(headers=headers)
@v2_bp.route(BLOB_DIGEST_ROUTE, methods=['GET'])
@ -124,13 +122,15 @@ def start_blob_upload(namespace_name, repo_name):
digest = request.args.get('digest', None)
if digest is None:
# Short-circuit because the user will send the blob data in another request.
accepted = make_response('', 202)
accepted.headers['Location'] = url_for('v2.upload_chunk',
repository='%s/%s' % (namespace_name, repo_name),
upload_uuid=new_upload_uuid)
accepted.headers['Range'] = _render_range(0)
accepted.headers['Docker-Upload-UUID'] = new_upload_uuid
return accepted
return Response(
status=202,
headers={
'Docker-Upload-UUID': new_upload_uuid,
'Range': _render_range(0),
'Location': url_for('v2.upload_chunk', repository='%s/%s' % (namespace_name, repo_name),
upload_uuid=new_upload_uuid)
},
)
# The user plans to send us the entire body right now.
# Find the upload.
@ -151,12 +151,14 @@ def start_blob_upload(namespace_name, repo_name):
_finish_upload(namespace_name, repo_name, updated_blob_upload, digest)
# Write the response to the docker client.
response = make_response('', 201)
response.headers['Docker-Content-Digest'] = digest
response.headers['Location'] = url_for('v2.download_blob',
repository='%s/%s' % (namespace_name, repo_name),
digest=digest)
return response
return Response(
status=201,
headers={
'Docker-Content-Digest': digest,
'Location': url_for('v2.download_blob', repository='%s/%s' % (namespace_name, repo_name),
digest=digest),
},
)
@v2_bp.route('/<repopath:repository>/blobs/uploads/<upload_uuid>', methods=['GET'])
@ -169,12 +171,13 @@ def fetch_existing_upload(namespace_name, repo_name, upload_uuid):
if blob_upload is None:
raise BlobUploadUnknown()
accepted = make_response('', 204)
accepted.headers.extend({
'Docker-Upload-UUID': upload_uuid,
'Range': _render_range(blob_upload.byte_count+1), # Docker byte ranges are exclusive
})
return accepted
return Response(
status=204,
headers={
'Docker-Upload-UUID': upload_uuid,
'Range': _render_range(blob_upload.byte_count+1), # Docker byte ranges are exclusive
},
)
@v2_bp.route('/<repopath:repository>/blobs/uploads/<upload_uuid>', methods=['PATCH'])
@ -198,13 +201,14 @@ def upload_chunk(namespace_name, repo_name, upload_uuid):
v2.update_blob_upload(updated_blob_upload)
# Write the response to the Docker client.
accepted = make_response('', 204)
accepted.headers.extend({
'Location': _current_request_path(),
'Range': _render_range(updated_blob_upload.byte_count, with_bytes_prefix=False),
'Docker-Upload-UUID': upload_uuid,
})
return accepted
return Response(
status=204,
headers={
'Location': _current_request_path(),
'Range': _render_range(updated_blob_upload.byte_count, with_bytes_prefix=False),
'Docker-Upload-UUID': upload_uuid,
},
)
@v2_bp.route('/<repopath:repository>/blobs/uploads/<upload_uuid>', methods=['PUT'])
@ -233,13 +237,14 @@ def monolithic_upload_or_last_chunk(namespace_name, repo_name, upload_uuid):
_finish_upload(namespace_name, repo_name, updated_blob_upload, digest)
# Write the response to the Docker client.
response = make_response('', 201)
response.headers.extend({
'Docker-Content-Digest': digest,
'Location': url_for('v2.download_blob', repository='%s/%s' % (namespace_name, repo_name),
digest=digest)
})
return response
return Response(
status=201,
headers={
'Docker-Content-Digest': digest,
'Location': url_for('v2.download_blob', repository='%s/%s' % (namespace_name, repo_name),
digest=digest),
}
)
@v2_bp.route('/<repopath:repository>/blobs/uploads/<upload_uuid>', methods=['DELETE'])
@ -257,7 +262,7 @@ def cancel_upload(namespace_name, repo_name, upload_uuid):
v2.delete_blob_upload(upload_uuid)
storage.cancel_chunked_upload({upload.location_name}, upload.uuid, upload.storage_metadata)
return make_response('', 204)
return Response(status=204)
@v2_bp.route('/<repopath:repository>/blobs/<digest>', methods=['DELETE'])
@ -288,13 +293,9 @@ def _abort_range_not_satisfiable(valid_end, upload_uuid):
TODO(jzelinskie): Unify this with the V2RegistryException class.
"""
invalid_range = make_response('', 416)
invalid_range.headers.extend({
'Location': _current_request_path(),
'Range': '0-{0}'.format(valid_end),
'Docker-Upload-UUID': upload_uuid,
})
flask_abort(invalid_range)
flask_abort(Response(status=416, headers={'Location': _current_request_path(),
'Range': '0-{0}'.format(valid_end),
'Docker-Upload-UUID': upload_uuid}))
def _parse_range_header(range_header_text):