in sdk/src/azure/core/az_http_response.c [282:318]
AZ_NODISCARD az_result az_http_response_get_body(az_http_response* ref_response, az_span* out_body)
{
_az_PRECONDITION_NOT_NULL(ref_response);
_az_PRECONDITION_NOT_NULL(out_body);
// Make sure get body works no matter where is the current parsing. Allow users to call get body
// directly and ignore headers and status line
_az_http_response_kind current_parsing_section = ref_response->_internal.parser.next_kind;
if (current_parsing_section != _az_HTTP_RESPONSE_KIND_BODY)
{
if (current_parsing_section == _az_HTTP_RESPONSE_KIND_EOF
|| current_parsing_section == _az_HTTP_RESPONSE_KIND_STATUS_LINE)
{
// Reset parser and get status line
az_http_response_status_line ignore = { 0 };
_az_RETURN_IF_FAILED(az_http_response_get_status_line(ref_response, &ignore));
// update current parsing section
current_parsing_section = ref_response->_internal.parser.next_kind;
}
// parse any remaining header
if (current_parsing_section == _az_HTTP_RESPONSE_KIND_HEADER)
{
// Parse and ignore all remaining headers
for (az_span n = { 0 }, v = { 0 };
az_result_succeeded(az_http_response_get_next_header(ref_response, &n, &v));)
{
// ignoring header
}
}
}
// take all the remaining content from reader as body
*out_body = az_span_slice_to_end(ref_response->_internal.parser.remaining, 0);
ref_response->_internal.parser.next_kind = _az_HTTP_RESPONSE_KIND_EOF;
return AZ_OK;
}