Skip to content

Commit

Permalink
More reliable way to check if there is anything in result IOStream
Browse files Browse the repository at this point in the history
Signed-off-by: JaySon-Huang <[email protected]>
  • Loading branch information
JaySon-Huang committed Apr 6, 2023
1 parent 6b93c6e commit 75b6642
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/aws-cpp-sdk-core/source/client/AWSJsonClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ JsonOutcome AWSJsonClient::MakeRequest(const Aws::Http::URI& uri,
return JsonOutcome(std::move(httpOutcome));
}

if (httpOutcome.GetResult()->GetResponseBody().tellp() > 0)
if (httpOutcome.GetResult()->GetResponseBody().peek() != std::char_traits<char>::eof())
//this is stupid, but gcc doesn't pick up the covariant on the dereference so we have to give it a little hint.
return JsonOutcome(AmazonWebServiceResult<JsonValue>(JsonValue(httpOutcome.GetResult()->GetResponseBody()),
httpOutcome.GetResult()->GetHeaders(),
Expand All @@ -129,7 +129,7 @@ JsonOutcome AWSJsonClient::MakeRequest(const Aws::Http::URI& uri,
return JsonOutcome(std::move(httpOutcome));
}

if (httpOutcome.GetResult()->GetResponseBody().tellp() > 0)
if (httpOutcome.GetResult()->GetResponseBody().peek() != std::char_traits<char>::eof())
{
JsonValue jsonValue(httpOutcome.GetResult()->GetResponseBody());
if (!jsonValue.WasParseSuccessful())
Expand Down Expand Up @@ -162,7 +162,7 @@ JsonOutcome AWSJsonClient::MakeEventStreamRequest(std::shared_ptr<Aws::Http::Htt

HttpResponseOutcome httpOutcome(std::move(httpResponse));

if (httpOutcome.GetResult()->GetResponseBody().tellp() > 0)
if (httpOutcome.GetResult()->GetResponseBody().peek() != std::char_traits<char>::eof())
{
JsonValue jsonValue(httpOutcome.GetResult()->GetResponseBody());
if (!jsonValue.WasParseSuccessful())
Expand All @@ -188,7 +188,7 @@ AWSError<CoreErrors> AWSJsonClient::BuildAWSError(
bool retryable = httpResponse->GetClientErrorType() == CoreErrors::NETWORK_CONNECTION ? true : false;
error = AWSError<CoreErrors>(httpResponse->GetClientErrorType(), "", httpResponse->GetClientErrorMessage(), retryable);
}
else if (!httpResponse->GetResponseBody() || httpResponse->GetResponseBody().tellp() < 1)
else if (!httpResponse->GetResponseBody() || httpResponse->GetResponseBody().peek() == std::char_traits<char>::eof())
{
auto responseCode = httpResponse->GetResponseCode();
auto errorCode = AWSClient::GuessBodylessErrorType(responseCode);
Expand Down
6 changes: 3 additions & 3 deletions src/aws-cpp-sdk-core/source/client/AWSXmlClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ XmlOutcome AWSXMLClient::MakeRequest(const Aws::Http::URI& uri,
return XmlOutcome(std::move(httpOutcome));
}

if (httpOutcome.GetResult()->GetResponseBody().tellp() > 0)
if (httpOutcome.GetResult()->GetResponseBody().peek() != std::char_traits<char>::eof())
{
XmlDocument xmlDoc = XmlDocument::CreateFromXmlStream(httpOutcome.GetResult()->GetResponseBody());

Expand Down Expand Up @@ -132,7 +132,7 @@ XmlOutcome AWSXMLClient::MakeRequest(const Aws::Http::URI& uri,
return XmlOutcome(std::move(httpOutcome));
}

if (httpOutcome.GetResult()->GetResponseBody().tellp() > 0)
if (httpOutcome.GetResult()->GetResponseBody().peek() != std::char_traits<char>::eof())
{
return XmlOutcome(AmazonWebServiceResult<XmlDocument>(
XmlDocument::CreateFromXmlStream(httpOutcome.GetResult()->GetResponseBody()),
Expand All @@ -150,7 +150,7 @@ AWSError<CoreErrors> AWSXMLClient::BuildAWSError(const std::shared_ptr<Http::Htt
bool retryable = httpResponse->GetClientErrorType() == CoreErrors::NETWORK_CONNECTION ? true : false;
error = AWSError<CoreErrors>(httpResponse->GetClientErrorType(), "", httpResponse->GetClientErrorMessage(), retryable);
}
else if (!httpResponse->GetResponseBody() || httpResponse->GetResponseBody().tellp() < 1)
else if (!httpResponse->GetResponseBody() || httpResponse->GetResponseBody().peek() == std::char_traits<char>::eof())
{
auto responseCode = httpResponse->GetResponseCode();
auto errorCode = AWSClient::GuessBodylessErrorType(responseCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ namespace Aws
AWS_LOGSTREAM_ERROR(m_logtag.c_str(), "Http request to retrieve credentials failed");
return AWSError<CoreErrors>(CoreErrors::NETWORK_CONNECTION, true); // Retryable
}
else if (m_errorMarshaller && response->GetResponseBody().tellp() > 0)
else if (m_errorMarshaller && response->GetResponseBody().peek() != std::char_traits<char>::eof())
{
return m_errorMarshaller->Marshall(*response);
}
Expand Down

0 comments on commit 75b6642

Please sign in to comment.