esp_http_client: Support handling larger content lengths

Closes https://github.com/espressif/esp-idf/issues/6580
pull/7830/head
Shubham Kulkarni 2021-10-25 18:57:07 +05:30 zatwierdzone przez bot
rodzic 436249de4f
commit 5bf49e1cd6
3 zmienionych plików z 39 dodań i 39 usunięć

Wyświetl plik

@ -44,10 +44,10 @@ typedef struct {
http_header_handle_t headers; /*!< http header */
esp_http_buffer_t *buffer; /*!< data buffer as linked list */
int status_code; /*!< status code (integer) */
int content_length; /*!< data length */
int64_t content_length; /*!< data length */
int chunk_length; /*!< chunk length */
int data_offset; /*!< offset to http data (Skip header) */
int data_process; /*!< data processed */
int64_t data_process; /*!< data processed */
int method; /*!< http method */
bool is_chunked;
} esp_http_data_t;
@ -932,7 +932,7 @@ static int esp_http_client_get_data(esp_http_client_handle_t client)
esp_http_buffer_t *res_buffer = client->response->buffer;
ESP_LOGD(TAG, "data_process=%d, content_length=%d", client->response->data_process, client->response->content_length);
ESP_LOGD(TAG, "data_process=%lld, content_length=%lld", client->response->data_process, client->response->content_length);
int rlen = esp_transport_read(client->transport, res_buffer->data, client->buffer_size_rx, client->timeout_ms);
if (rlen >= 0) {
@ -950,7 +950,7 @@ bool esp_http_client_is_complete_data_received(esp_http_client_handle_t client)
}
} else {
if (client->response->data_process != client->response->content_length) {
ESP_LOGD(TAG, "Data processed %d != Data specified in content length %d", client->response->data_process, client->response->content_length);
ESP_LOGD(TAG, "Data processed %lld != Data specified in content length %lld", client->response->data_process, client->response->content_length);
return false;
}
}
@ -980,7 +980,7 @@ int esp_http_client_read(esp_http_client_handle_t client, char *buffer, int len)
} else {
is_data_remain = client->response->data_process < client->response->content_length;
}
ESP_LOGD(TAG, "is_data_remain=%d, is_chunked=%d, content_length=%d", is_data_remain, client->response->is_chunked, client->response->content_length);
ESP_LOGD(TAG, "is_data_remain=%d, is_chunked=%d, content_length=%lld", is_data_remain, client->response->is_chunked, client->response->content_length);
if (!is_data_remain) {
break;
}
@ -1129,7 +1129,7 @@ esp_err_t esp_http_client_perform(esp_http_client_handle_t client)
return ESP_OK;
}
int esp_http_client_fetch_headers(esp_http_client_handle_t client)
int64_t esp_http_client_fetch_headers(esp_http_client_handle_t client)
{
if (client->state < HTTP_STATE_REQ_COMPLETE_HEADER) {
return ESP_FAIL;
@ -1146,7 +1146,7 @@ int esp_http_client_fetch_headers(esp_http_client_handle_t client)
}
http_parser_execute(client->parser, client->parser_settings, buffer->data, buffer->len);
}
ESP_LOGD(TAG, "content_length = %d", client->response->content_length);
ESP_LOGD(TAG, "content_length = %lld", client->response->content_length);
if (client->response->content_length <= 0) {
client->response->is_chunked = true;
return 0;
@ -1413,7 +1413,7 @@ int esp_http_client_get_status_code(esp_http_client_handle_t client)
return client->response->status_code;
}
int esp_http_client_get_content_length(esp_http_client_handle_t client)
int64_t esp_http_client_get_content_length(esp_http_client_handle_t client)
{
return client->response->content_length;
}

Wyświetl plik

@ -415,7 +415,7 @@ int esp_http_client_write(esp_http_client_handle_t client, const char *buffer, i
* - (-1: ESP_FAIL) if any errors
* - Download data length defined by content-length header
*/
int esp_http_client_fetch_headers(esp_http_client_handle_t client);
int64_t esp_http_client_fetch_headers(esp_http_client_handle_t client);
/**
@ -460,7 +460,7 @@ int esp_http_client_get_status_code(esp_http_client_handle_t client);
* - (-1) Chunked transfer
* - Content-Length value as bytes
*/
int esp_http_client_get_content_length(esp_http_client_handle_t client);
int64_t esp_http_client_get_content_length(esp_http_client_handle_t client);
/**
* @brief Close http connection, still kept all http request resources

Wyświetl plik

@ -136,7 +136,7 @@ static void http_rest_with_url(void)
// GET
esp_err_t err = esp_http_client_perform(client);
if (err == ESP_OK) {
ESP_LOGI(TAG, "HTTP GET Status = %d, content_length = %d",
ESP_LOGI(TAG, "HTTP GET Status = %d, content_length = %lld",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
@ -152,7 +152,7 @@ static void http_rest_with_url(void)
esp_http_client_set_post_field(client, post_data, strlen(post_data));
err = esp_http_client_perform(client);
if (err == ESP_OK) {
ESP_LOGI(TAG, "HTTP POST Status = %d, content_length = %d",
ESP_LOGI(TAG, "HTTP POST Status = %d, content_length = %lld",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
@ -164,7 +164,7 @@ static void http_rest_with_url(void)
esp_http_client_set_method(client, HTTP_METHOD_PUT);
err = esp_http_client_perform(client);
if (err == ESP_OK) {
ESP_LOGI(TAG, "HTTP PUT Status = %d, content_length = %d",
ESP_LOGI(TAG, "HTTP PUT Status = %d, content_length = %lld",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
@ -177,7 +177,7 @@ static void http_rest_with_url(void)
esp_http_client_set_post_field(client, NULL, 0);
err = esp_http_client_perform(client);
if (err == ESP_OK) {
ESP_LOGI(TAG, "HTTP PATCH Status = %d, content_length = %d",
ESP_LOGI(TAG, "HTTP PATCH Status = %d, content_length = %lld",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
@ -189,7 +189,7 @@ static void http_rest_with_url(void)
esp_http_client_set_method(client, HTTP_METHOD_DELETE);
err = esp_http_client_perform(client);
if (err == ESP_OK) {
ESP_LOGI(TAG, "HTTP DELETE Status = %d, content_length = %d",
ESP_LOGI(TAG, "HTTP DELETE Status = %d, content_length = %lld",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
@ -201,7 +201,7 @@ static void http_rest_with_url(void)
esp_http_client_set_method(client, HTTP_METHOD_HEAD);
err = esp_http_client_perform(client);
if (err == ESP_OK) {
ESP_LOGI(TAG, "HTTP HEAD Status = %d, content_length = %d",
ESP_LOGI(TAG, "HTTP HEAD Status = %d, content_length = %lld",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
@ -224,7 +224,7 @@ static void http_rest_with_hostname_path(void)
// GET
esp_err_t err = esp_http_client_perform(client);
if (err == ESP_OK) {
ESP_LOGI(TAG, "HTTP GET Status = %d, content_length = %d",
ESP_LOGI(TAG, "HTTP GET Status = %d, content_length = %lld",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
@ -238,7 +238,7 @@ static void http_rest_with_hostname_path(void)
esp_http_client_set_post_field(client, post_data, strlen(post_data));
err = esp_http_client_perform(client);
if (err == ESP_OK) {
ESP_LOGI(TAG, "HTTP POST Status = %d, content_length = %d",
ESP_LOGI(TAG, "HTTP POST Status = %d, content_length = %lld",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
@ -250,7 +250,7 @@ static void http_rest_with_hostname_path(void)
esp_http_client_set_method(client, HTTP_METHOD_PUT);
err = esp_http_client_perform(client);
if (err == ESP_OK) {
ESP_LOGI(TAG, "HTTP PUT Status = %d, content_length = %d",
ESP_LOGI(TAG, "HTTP PUT Status = %d, content_length = %lld",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
@ -263,7 +263,7 @@ static void http_rest_with_hostname_path(void)
esp_http_client_set_post_field(client, NULL, 0);
err = esp_http_client_perform(client);
if (err == ESP_OK) {
ESP_LOGI(TAG, "HTTP PATCH Status = %d, content_length = %d",
ESP_LOGI(TAG, "HTTP PATCH Status = %d, content_length = %lld",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
@ -275,7 +275,7 @@ static void http_rest_with_hostname_path(void)
esp_http_client_set_method(client, HTTP_METHOD_DELETE);
err = esp_http_client_perform(client);
if (err == ESP_OK) {
ESP_LOGI(TAG, "HTTP DELETE Status = %d, content_length = %d",
ESP_LOGI(TAG, "HTTP DELETE Status = %d, content_length = %lld",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
@ -287,7 +287,7 @@ static void http_rest_with_hostname_path(void)
esp_http_client_set_method(client, HTTP_METHOD_HEAD);
err = esp_http_client_perform(client);
if (err == ESP_OK) {
ESP_LOGI(TAG, "HTTP HEAD Status = %d, content_length = %d",
ESP_LOGI(TAG, "HTTP HEAD Status = %d, content_length = %lld",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
@ -317,7 +317,7 @@ static void http_auth_basic(void)
esp_err_t err = esp_http_client_perform(client);
if (err == ESP_OK) {
ESP_LOGI(TAG, "HTTP Basic Auth Status = %d, content_length = %d",
ESP_LOGI(TAG, "HTTP Basic Auth Status = %d, content_length = %lld",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
@ -336,7 +336,7 @@ static void http_auth_basic_redirect(void)
esp_err_t err = esp_http_client_perform(client);
if (err == ESP_OK) {
ESP_LOGI(TAG, "HTTP Basic Auth redirect Status = %d, content_length = %d",
ESP_LOGI(TAG, "HTTP Basic Auth redirect Status = %d, content_length = %lld",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
@ -357,7 +357,7 @@ static void http_auth_digest(void)
esp_err_t err = esp_http_client_perform(client);
if (err == ESP_OK) {
ESP_LOGI(TAG, "HTTP Digest Auth Status = %d, content_length = %d",
ESP_LOGI(TAG, "HTTP Digest Auth Status = %d, content_length = %lld",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
@ -378,7 +378,7 @@ static void https_with_url(void)
esp_err_t err = esp_http_client_perform(client);
if (err == ESP_OK) {
ESP_LOGI(TAG, "HTTPS Status = %d, content_length = %d",
ESP_LOGI(TAG, "HTTPS Status = %d, content_length = %lld",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
@ -400,7 +400,7 @@ static void https_with_hostname_path(void)
esp_err_t err = esp_http_client_perform(client);
if (err == ESP_OK) {
ESP_LOGI(TAG, "HTTPS Status = %d, content_length = %d",
ESP_LOGI(TAG, "HTTPS Status = %d, content_length = %lld",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
@ -419,7 +419,7 @@ static void http_relative_redirect(void)
esp_err_t err = esp_http_client_perform(client);
if (err == ESP_OK) {
ESP_LOGI(TAG, "HTTP Relative path redirect Status = %d, content_length = %d",
ESP_LOGI(TAG, "HTTP Relative path redirect Status = %d, content_length = %lld",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
@ -438,7 +438,7 @@ static void http_absolute_redirect(void)
esp_err_t err = esp_http_client_perform(client);
if (err == ESP_OK) {
ESP_LOGI(TAG, "HTTP Absolute path redirect Status = %d, content_length = %d",
ESP_LOGI(TAG, "HTTP Absolute path redirect Status = %d, content_length = %lld",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
@ -457,7 +457,7 @@ static void http_redirect_to_https(void)
esp_err_t err = esp_http_client_perform(client);
if (err == ESP_OK) {
ESP_LOGI(TAG, "HTTP redirect to HTTPS Status = %d, content_length = %d",
ESP_LOGI(TAG, "HTTP redirect to HTTPS Status = %d, content_length = %lld",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
@ -477,7 +477,7 @@ static void http_download_chunk(void)
esp_err_t err = esp_http_client_perform(client);
if (err == ESP_OK) {
ESP_LOGI(TAG, "HTTP chunk encoding Status = %d, content_length = %d",
ESP_LOGI(TAG, "HTTP chunk encoding Status = %d, content_length = %lld",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
@ -513,7 +513,7 @@ static void http_perform_as_stream_reader(void)
buffer[read_len] = 0;
ESP_LOGD(TAG, "read_len = %d", read_len);
}
ESP_LOGI(TAG, "HTTP Stream reader Status = %d, content_length = %d",
ESP_LOGI(TAG, "HTTP Stream reader Status = %d, content_length = %lld",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
esp_http_client_close(client);
@ -545,7 +545,7 @@ static void https_async(void)
}
}
if (err == ESP_OK) {
ESP_LOGI(TAG, "HTTPS Status = %d, content_length = %d",
ESP_LOGI(TAG, "HTTPS Status = %d, content_length = %lld",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
@ -564,7 +564,7 @@ static void https_with_invalid_url(void)
esp_err_t err = esp_http_client_perform(client);
if (err == ESP_OK) {
ESP_LOGI(TAG, "HTTPS Status = %d, content_length = %d",
ESP_LOGI(TAG, "HTTPS Status = %d, content_length = %lld",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
@ -600,7 +600,7 @@ static void http_native_request(void)
} else {
int data_read = esp_http_client_read_response(client, output_buffer, MAX_HTTP_OUTPUT_BUFFER);
if (data_read >= 0) {
ESP_LOGI(TAG, "HTTP GET Status = %d, content_length = %d",
ESP_LOGI(TAG, "HTTP GET Status = %d, content_length = %lld",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
ESP_LOG_BUFFER_HEX(TAG, output_buffer, data_read);
@ -630,7 +630,7 @@ static void http_native_request(void)
} else {
int data_read = esp_http_client_read_response(client, output_buffer, MAX_HTTP_OUTPUT_BUFFER);
if (data_read >= 0) {
ESP_LOGI(TAG, "HTTP POST Status = %d, content_length = %d",
ESP_LOGI(TAG, "HTTP POST Status = %d, content_length = %lld",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
ESP_LOG_BUFFER_HEX(TAG, output_buffer, strlen(output_buffer));
@ -654,7 +654,7 @@ static void http_partial_download(void)
esp_http_client_set_header(client, "Range", "bytes=10-");
esp_err_t err = esp_http_client_perform(client);
if (err == ESP_OK) {
ESP_LOGI(TAG, "HTTP Status = %d, content_length = %d",
ESP_LOGI(TAG, "HTTP Status = %d, content_length = %lld",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
@ -665,7 +665,7 @@ static void http_partial_download(void)
esp_http_client_set_header(client, "Range", "bytes=-10");
err = esp_http_client_perform(client);
if (err == ESP_OK) {
ESP_LOGI(TAG, "HTTP Status = %d, content_length = %d",
ESP_LOGI(TAG, "HTTP Status = %d, content_length = %lld",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
@ -676,7 +676,7 @@ static void http_partial_download(void)
esp_http_client_set_header(client, "Range", "bytes=11-20");
err = esp_http_client_perform(client);
if (err == ESP_OK) {
ESP_LOGI(TAG, "HTTP Status = %d, content_length = %d",
ESP_LOGI(TAG, "HTTP Status = %d, content_length = %lld",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {