in src/aws-cpp-sdk-core/source/http/curl/CurlHttpClient.cpp [300:359]
static size_t ReadBody(char* ptr, size_t size, size_t nmemb, void* userdata, bool isStreaming)
{
CurlReadCallbackContext* context = reinterpret_cast<CurlReadCallbackContext*>(userdata);
if(context == nullptr)
{
return 0;
}
const CurlHttpClient* client = context->m_client;
if(!client->ContinueRequest(*context->m_request) || !client->IsRequestProcessingEnabled())
{
return CURL_READFUNC_ABORT;
}
HttpRequest* request = context->m_request;
const std::shared_ptr<Aws::IOStream>& ioStream = request->GetContentBody();
size_t amountToRead = size * nmemb;
bool isAwsChunked = request->HasHeader(Aws::Http::CONTENT_ENCODING_HEADER) &&
request->GetHeaderValue(Aws::Http::CONTENT_ENCODING_HEADER).find(Aws::Http::AWS_CHUNKED_VALUE) != Aws::String::npos;
if (ioStream != nullptr && amountToRead > 0)
{
size_t amountRead = 0;
if (isStreaming) {
if (ioStream->bad()) {
AWS_LOGSTREAM_ERROR(CURL_HTTP_CLIENT_TAG, "Input stream is bad!");
return CURL_READFUNC_ABORT;
}
const int peekVal = ioStream->peek();
if (peekVal == ConcurrentStreamBuf::noData) {
return CURL_READFUNC_PAUSE;
}
if (ioStream->eof() || peekVal == EOF) {
return 0;
}
amountRead = (size_t)ioStream->readsome(ptr, amountToRead);
} else if (isAwsChunked && context->m_chunkedStream != nullptr) {
amountRead = context->m_chunkedStream->BufferedRead(ptr, amountToRead);
} else {
ioStream->read(ptr, amountToRead);
amountRead = static_cast<size_t>(ioStream->gcount());
}
auto& sentHandler = request->GetDataSentEventHandler();
if (sentHandler)
{
sentHandler(request, static_cast<long long>(amountRead));
}
if (context->m_rateLimiter)
{
context->m_rateLimiter->ApplyAndPayForCost(static_cast<int64_t>(amountRead));
}
return amountRead;
}
return 0;
}