Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions googleapiclient/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -1062,10 +1062,14 @@ def next_chunk(self, http=None, num_retries=0):
"Content-Length": str(chunk_end - self.resumable_progress + 1),
}

# An empty file results in chunk_end = -1 and size = 0
# sending "bytes 0--1/0" results in an invalid request
# Only add header "Content-Range" if chunk_end != -1
if chunk_end != -1:
if chunk_end - self.resumable_progress + 1 == 0 and chunk_end != -1:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest assigning

content_length = chunk_end - self.resumable_progress + 1 == 0 and chunk_end

before the headers = ... line and using content_length both for the header and in this conditional.

# This is the last chunk, it's empty but the file is not empty.
# Send a Content-Range that ends this file.
headers["Content-Range"] = "bytes */%s" % (size,)
elif chunk_end != -1:
# An empty file results in chunk_end = -1 and size = 0
# sending "bytes 0--1/0" results in an invalid request
# Only add header "Content-Range" if chunk_end != -1
headers["Content-Range"] = "bytes %d-%d/%s" % (
self.resumable_progress,
chunk_end,
Expand Down
Loading