Skip to content

Commit cbb612e

Browse files
author
Jonathan Hseu
committed
Upon any HTTP error, clear the response buffer.
Change: 149062390
1 parent aee4914 commit cbb612e

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

tensorflow/core/platform/cloud/http_request.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,15 +383,18 @@ Status HttpRequest::Send() {
383383
return Status::OK();
384384
case 401:
385385
case 403:
386+
response_buffer_->clear();
386387
return errors::PermissionDenied(error_message);
387388
case 404:
389+
response_buffer_->clear();
388390
return errors::NotFound(error_message);
389391
case 416: // Requested Range Not Satisfiable
390392
response_buffer_->clear();
391393
return Status::OK();
392394
default:
393395
// UNAVAILABLE can be retried by the caller, e.g by
394396
// RetryingFileSystem.
397+
response_buffer_->clear();
395398
return errors::Unavailable(error_message);
396399
}
397400
}

tensorflow/core/platform/cloud/http_request_test.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,5 +528,24 @@ TEST(HttpRequestTest, EscapeString) {
528528
EXPECT_EQ("a%2Fb%2Fc", http_request.EscapeString(test_string));
529529
}
530530

531+
TEST(HttpRequestTest, ErrorReturnsNoResponse) {
532+
FakeLibCurl libcurl("get response", 500);
533+
HttpRequest http_request(&libcurl);
534+
TF_EXPECT_OK(http_request.Init());
535+
536+
std::vector<char> scratch;
537+
scratch.insert(scratch.begin(), kTestContent.begin(), kTestContent.end());
538+
StringPiece result;
539+
scratch.reserve(100);
540+
541+
TF_EXPECT_OK(http_request.SetUri("http://www.testuri.com"));
542+
TF_EXPECT_OK(http_request.AddAuthBearerHeader("fake-bearer"));
543+
TF_EXPECT_OK(http_request.SetRange(100, 199));
544+
TF_EXPECT_OK(http_request.SetResultBuffer(&scratch));
545+
EXPECT_EQ(error::UNAVAILABLE, http_request.Send().code());
546+
547+
EXPECT_EQ("", string(scratch.begin(), scratch.end()));
548+
}
549+
531550
} // namespace
532551
} // namespace tensorflow

0 commit comments

Comments
 (0)