@@ -52,6 +52,7 @@ typedef struct {
52
52
esp_http_buffer_t * buffer ; /*!< data buffer as linked list */
53
53
int status_code ; /*!< status code (integer) */
54
54
int content_length ; /*!< data length */
55
+ int chunk_length ; /*!< chunk length */
55
56
int data_offset ; /*!< offset to http data (Skip header) */
56
57
int data_process ; /*!< data processed */
57
58
int method ; /*!< http method */
@@ -269,6 +270,14 @@ static int http_on_chunk_complete(http_parser *parser)
269
270
return 0 ;
270
271
}
271
272
273
+ static int http_on_chunk_header (http_parser * parser )
274
+ {
275
+ esp_http_client_handle_t client = parser -> data ;
276
+ client -> response -> chunk_length = parser -> content_length ;
277
+ ESP_LOGD (TAG , "http_on_chunk_header, chunk_length" );
278
+ return 0 ;
279
+ }
280
+
272
281
esp_err_t esp_http_client_set_header (esp_http_client_handle_t client , const char * key , const char * value )
273
282
{
274
283
return http_header_set (client -> request -> headers , key , value );
@@ -604,6 +613,7 @@ esp_http_client_handle_t esp_http_client_init(const esp_http_client_config_t *co
604
613
client -> parser_settings -> on_body = http_on_body ;
605
614
client -> parser_settings -> on_message_complete = http_on_message_complete ;
606
615
client -> parser_settings -> on_chunk_complete = http_on_chunk_complete ;
616
+ client -> parser_settings -> on_chunk_header = http_on_chunk_header ;
607
617
client -> parser -> data = client ;
608
618
client -> event .client = client ;
609
619
@@ -1357,3 +1367,17 @@ esp_err_t esp_http_client_get_url(esp_http_client_handle_t client, char *url, co
1357
1367
}
1358
1368
return ESP_FAIL ;
1359
1369
}
1370
+
1371
+ esp_err_t esp_http_client_get_chunk_length (esp_http_client_handle_t client , int * len )
1372
+ {
1373
+ if (client == NULL || len == NULL ) {
1374
+ return ESP_ERR_INVALID_ARG ;
1375
+ }
1376
+ if (esp_http_client_is_chunked_response (client )) {
1377
+ * len = client -> response -> chunk_length ;
1378
+ } else {
1379
+ ESP_LOGE (TAG , "Response is not chunked" );
1380
+ return ESP_FAIL ;
1381
+ }
1382
+ return ESP_OK ;
1383
+ }
0 commit comments