Skip to content

Commit

Permalink
Account for the case when GCS Resumable Upload returns a Range header…
Browse files Browse the repository at this point in the history
… prefixed with "bytes=".

Change: 136211474
  • Loading branch information
rinugun authored and tensorflower-gardener committed Oct 14, 2016
1 parent f8373db commit 5c1821b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tensorflow/core/platform/cloud/gcs_file_system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,10 @@ class GcsWritableFile : public WritableFile {
// This means GCS doesn't have any bytes of the file yet.
*uploaded = 0;
} else {
StringPiece range_piece(received_range);
range_piece.Consume("bytes="); // May or may not be present.
std::vector<int32> range_parts;
if (!str_util::SplitAndParseAsInts(received_range, '-', &range_parts) ||
if (!str_util::SplitAndParseAsInts(range_piece, '-', &range_parts) ||
range_parts.size() != 2) {
return errors::Internal(strings::StrCat(
"Unexpected response from GCS when writing ", GetGcsPath(),
Expand Down
11 changes: 11 additions & 0 deletions tensorflow/core/platform/cloud/gcs_file_system_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,17 @@ TEST(GcsFileSystemTest, NewWritableFile_ResumeUploadSucceeds) {
"Auth Token: fake_token\n"
"Header Content-Range: bytes 11-16/17\n"
"Put body: ntent2\n",
"", errors::Unavailable("503"), 503),
new FakeHttpRequest("Uri: https://custom/upload/location\n"
"Auth Token: fake_token\n"
"Header Content-Range: bytes */17\n"
"Put: yes\n",
"", errors::Unavailable("308"), nullptr,
{{"Range", "bytes=0-12"}}, 308),
new FakeHttpRequest("Uri: https://custom/upload/location\n"
"Auth Token: fake_token\n"
"Header Content-Range: bytes 13-16/17\n"
"Put body: ent2\n",
"")});
GcsFileSystem fs(std::unique_ptr<AuthProvider>(new FakeAuthProvider),
std::unique_ptr<HttpRequest::Factory>(
Expand Down

0 comments on commit 5c1821b

Please sign in to comment.