Fix PATCH semantics due to recent API changes

This commit is contained in:
Joseph Schorr 2015-08-13 15:35:37 -04:00
parent f50ea3329a
commit bc4e07343e

View file

@ -109,8 +109,8 @@ def download_blob(namespace, repo_name, digest):
return Response(storage.stream_read(found.locations, path), headers=headers)
def _render_range(end_byte):
return 'bytes=0-{0}'.format(end_byte)
def _render_range(end_byte, with_bytes_prefix=True):
return '{0}0-{1}'.format('bytes=' if with_bytes_prefix else '', end_byte - 1)
@v2_bp.route('/<namespace>/<repo_name>/blobs/uploads/', methods=['POST'])
@ -195,7 +195,6 @@ def _upload_chunk(namespace, repo_name, upload_uuid, range_required):
start_offset, length = 0, -1
range_header = request.headers.get('range', None)
if range_required and range_header is None:
_range_not_satisfiable(found.byte_count)
@ -208,11 +207,12 @@ def _upload_chunk(namespace, repo_name, upload_uuid, range_required):
input_fp = wrap_with_hash(get_input_stream(request), found.sha_state)
try:
storage.stream_upload_chunk({found.location.name}, upload_uuid, start_offset, length, input_fp)
length_written = storage.stream_upload_chunk({found.location.name}, upload_uuid, start_offset,
length, input_fp)
except InvalidChunkException:
_range_not_satisfiable(found.byte_count)
found.byte_count += length
found.byte_count += length_written
return found
@ -240,12 +240,12 @@ def _finish_upload(namespace, repo_name, upload_obj, expected_digest):
@require_repo_write
@anon_protect
def upload_chunk(namespace, repo_name, upload_uuid):
upload = _upload_chunk(namespace, repo_name, upload_uuid, range_required=True)
upload = _upload_chunk(namespace, repo_name, upload_uuid, range_required=False)
upload.save()
accepted = make_response('', 202)
accepted = make_response('', 204)
accepted.headers['Location'] = _current_request_path()
accepted.headers['Range'] = _render_range(upload.byte_count)
accepted.headers['Range'] = _render_range(upload.byte_count, with_bytes_prefix=False)
accepted.headers['Docker-Upload-UUID'] = upload_uuid
return accepted