Fix resumable upload support and add another test

This commit is contained in:
Joseph Schorr 2015-09-25 11:51:50 -04:00
parent 7ca04f41dd
commit 09f8ad695b
2 changed files with 55 additions and 11 deletions

View file

@ -167,7 +167,7 @@ def _range_not_satisfiable(valid_end):
flask_abort(invalid_range)
def _parse_range_header(range_header_text, valid_start):
def _parse_range_header(range_header_text):
""" Parses the range header, and returns a tuple of the start offset and the length,
or raises an _InvalidRangeHeader exception.
"""
@ -178,7 +178,7 @@ def _parse_range_header(range_header_text, valid_start):
start = int(found.group(1))
length = int(found.group(2)) - start
if start != valid_start or length <= 0:
if length <= 0:
raise _InvalidRangeHeader()
return (start, length)
@ -197,7 +197,7 @@ def _upload_chunk(namespace, repo_name, upload_uuid):
range_header = request.headers.get('range', None)
if range_header is not None:
try:
start_offset, length = _parse_range_header(range_header, found.byte_count)
start_offset, length = _parse_range_header(range_header)
except _InvalidRangeHeader:
_range_not_satisfiable(found.byte_count)
@ -205,10 +205,12 @@ def _upload_chunk(namespace, repo_name, upload_uuid):
_range_not_satisfiable(found.byte_count)
input_fp = get_input_stream(request)
if start_offset > 0 and start_offset < found.byte_count:
# Skip the bytes which were received on a previous push, which are already stored and
# included in the sha calculation
input_fp = StreamSlice(input_fp, found.byte_count - start_offset)
start_offset = found.byte_count
input_fp = wrap_with_handler(input_fp, found.sha_state.update)