esp_http_client: Add helper API to read larger data chunks from HTTP Stream

This commit is contained in:
Shubham Kulkarni 2020-03-12 19:12:27 +05:30
parent 6af3456ca3
commit 4858184e19
2 changed files with 27 additions and 0 deletions

View file

@ -1315,3 +1315,16 @@ void esp_http_client_add_auth(esp_http_client_handle_t client)
ESP_LOGW(TAG, "This request requires authentication, but does not provide header information for that");
}
}
int esp_http_client_read_response(esp_http_client_handle_t client, char *buffer, int len)
{
int read_len = 0;
while (read_len < len) {
int data_read = esp_http_client_read(client, buffer + read_len, len - read_len);
if (data_read <= 0) {
return read_len;
}
read_len += data_read;
}
return read_len;
}

View file

@ -497,6 +497,20 @@ void esp_http_client_add_auth(esp_http_client_handle_t client);
*/
bool esp_http_client_is_complete_data_received(esp_http_client_handle_t client);
/**
* @brief Helper API to read larger data chunks
* This is a helper API which internally calls `esp_http_client_read` multiple times till the end of data is reached or till the buffer gets full.
*
* @param[in] client The esp_http_client handle
* @param buffer The buffer
* @param[in] len The buffer length
*
* @return
* - Length of data was read
*/
int esp_http_client_read_response(esp_http_client_handle_t client, char *buffer, int len);
#ifdef __cplusplus
}
#endif