Having issue with http chunked response

devang.dixit
Posts: 13
Joined: Thu Aug 16, 2018 5:45 am

Having issue with http chunked response

Postby devang.dixit » Thu Aug 23, 2018 5:48 pm

int esp_http_client_fetch_headers(esp_http_client_handle_t client)
{
if (client->state < HTTP_STATE_REQ_COMPLETE_HEADER) {
return ESP_FAIL;
}
client->state = HTTP_STATE_REQ_COMPLETE_DATA;
esp_http_buffer_t *buffer = client->response->buffer;
client->response->status_code = -1;
while (client->state < HTTP_STATE_RES_COMPLETE_HEADER) {
buffer->len = transport_read(client->transport, buffer->data, client->buffer_size, client->timeout_ms);
if (buffer->len <= 0) {
return ESP_FAIL;
}
http_parser_execute(client->parser, client->parser_settings, buffer->data, buffer->len);
}
ESP_LOGD(TAG, "content_length = %d", client->response->content_length);
if (client->response->content_length <= 0) {
client->response->is_chunked = true;
return 0;
}
return client->response->content_length;
}
what should be client->buffer_size? as this is not fixed for every response and by default it take 512(client->buffer_size), so sometimes it also reads some part of body.
And for chuncked response this api returns 0 as content length? so what length to be used while calling esp_http_client_read(esp_http_client_handle_t client, char *buffer, int length);


devang.dixit
Posts: 13
Joined: Thu Aug 16, 2018 5:45 am

Re: Having issue with http chunked response

Postby devang.dixit » Sat Aug 25, 2018 5:22 am

thanks for the response,
But in my case HTTP_BUF_SIZE of the response is more than 512. so in the event handler when the event HTTP_EVENT_ON_HEADER occurs I printed the evt->header_key and evt->header_value, so for the first 5-6 headers it prints perfectly, but when it exceeds the HTTP_BUF_SIZE, it corrupted the 7th headers key, and when the next event occurs (in the second loop of esp_http_client_fetch_headers when it reads the next 512 bytes) the starting bytes(3 or 4) are omitted from the 7th header.
example:
actual header's key and value in response(value can be of any length).
header1 : value1
.
.
.
header7 : value7

from start of the first header upto 3rd byte of the 7th header's key(length is 512bytes).


Header key and value which i got when the event HTTP_EVENT_ON_HEADER occurs.
1st time the event occurs :- header1 : value1
2st time the event occurs :- header2 : value2
3st time the event occurs :- header3 : value3
.
.
.
7th time the event occurs :- der7 : value7 (this event occurs in the second loop of esp_http_client_fetch_headers and it omits the first 3bytes of the header)

So, I increased the size HTTP_BUF_SIZE to 650, but when the response header exceeds 650 length the again the above issue occurs.
Thats why I was asking that what should be HTTP_BUF_SIZE or client->buffer_size?

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: Having issue with http chunked response

Postby chegewara » Sat Aug 25, 2018 5:03 pm

Im guessing you should read headers and concatenate in one variable until read headers length is less than buffer size or 0, which means you have read all headers. Then you can perform any actions on headers.

formus14
Posts: 8
Joined: Wed Nov 15, 2017 3:22 pm

Re: Having issue with http chunked response

Postby formus14 » Tue Apr 30, 2019 11:25 am

Very important .. what value did you fill CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN in the menuconfig->mbedTLS section ?

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: Having issue with http chunked response

Postby chegewara » Wed May 01, 2019 10:02 am

Most likely it was default value (16kB).

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot], Majestic-12 [Bot] and 115 guests