esp-idf-svc icon indicating copy to clipboard operation
esp-idf-svc copied to clipboard

EspHttpClient doesn't support `keep-alive`

Open AnthonyGrondin opened this issue 3 years ago • 3 comments

Description

The current implementation of EspHttpClient doesn't support the keep-alive functionnality of HTTP connections.

According to the documentation, we can specify the following attributes to esp_http_client_config_t:

Also, the current implementation doesn't call esp_http_client_close after the keep-alive timeout or max as been reached.

Expected behavior

We should be able to pass the keep-alive attributes to EspHttpClientConfiguration either by specifiying each attributes, or by passing a struct, that contains the properties, whichever is the most idiomatic.

esp_http_client_close should also be called, after the connection has been idle for the number of seconds specified in timeout, or after reaching the maximum number of requests that can be sent on this connection.

External documentation

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive

AnthonyGrondin avatar Sep 07 '22 19:09 AnthonyGrondin

@AnthonyGrondin Would you be willing to contribute a PR against master for this?

ivmarkov avatar Sep 22 '22 09:09 ivmarkov

I don't think I have the required knowledge to come up with an ideal implementation of it.

The main challenge here, is to work asynchronously, since the implementation has to work kind of like a watchdog. Upon a new request, a timer is started, with the value of the keep-alive header, and decrements each second. If another request is made during that period, before the timer reaches 0, it has to be reset from the value of the keep-alive header in that request.

AnthonyGrondin avatar Sep 24 '22 04:09 AnthonyGrondin

I don't think I have the required knowledge to come up with an ideal implementation of it.

The main challenge here, is to work asynchronously, since the implementation has to work kind of like a watchdog. Upon a new request, a timer is started, with the value of the keep-alive header, and decrements each second. If another request is made during that period, before the timer reaches 0, it has to be reset from the value of the keep-alive header in that request.

Are you sure that Espressif does not have an automatic keep-alive management?

ivmarkov avatar Oct 01 '22 07:10 ivmarkov