throw runtime error if response is shorter than expected or gets closed (#577)
* throw runtime error if response is shorter than expected or gets closed * trhow Azure::Core::Http::TransportException
This commit is contained in:
parent
9eb4d41bfc
commit
0dce4de5a1
@ -525,6 +525,23 @@ int64_t CurlSession::Read(Azure::Core::Context const& context, uint8_t* buffer,
|
||||
totalRead = ReadFromSocket(buffer, static_cast<size_t>(readRequestLength));
|
||||
this->m_sessionTotalRead += totalRead;
|
||||
|
||||
// Reading 0 bytes means closed connection.
|
||||
// For known content length and chunked response, this means there is nothing else to read from
|
||||
// server or lost connection before getting full response.
|
||||
// For unknown response size, it means the end of response and it's fine.
|
||||
if (totalRead == 0 && (this->m_contentLength > 0 || this->m_isChunkedResponseType))
|
||||
{
|
||||
auto expectedToRead = this->m_isChunkedResponseType ? this->m_chunkSize : this->m_contentLength;
|
||||
if (this->m_sessionTotalRead < expectedToRead)
|
||||
{
|
||||
throw Azure::Core::Http::TransportException(
|
||||
"Connection closed before getting full response or response is less than expected. "
|
||||
"Expected response length = "
|
||||
+ std::to_string(expectedToRead)
|
||||
+ ". Read until now = " + std::to_string(this->m_sessionTotalRead));
|
||||
}
|
||||
}
|
||||
|
||||
return totalRead;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user