khoih-prog / AsyncHTTPSRequest_Generic

Simple Async HTTPS Request library, supporting GET, POST, PUT, PATCH, DELETE and HEAD, on top of AsyncTCP_SSL library for ESP32 (including ESP32_S2, ESP32_S3 and ESP32_C3), WT32_ETH01 (ESP32 + LAN8720). Supporting in the future for RP2040W, ESP8266, Portenta_H7, STM32 with built-in LAN8742A Ethernet, etc. Now you can send HTTP / HTTPS requests to multiple addresses and receive responses from them
GNU General Public License v3.0
19 stars 4 forks source link

setReuse feature #12

Closed rjjrbatarao closed 2 years ago

rjjrbatarao commented 2 years ago

This library is great, one problem though when connecting twice on the same host takes a long time, I was wondering if theres a feature you could add to reuse the connection to avoid doing ssl handshake again, this could reduce the request time significantly on second request.

khoih-prog commented 2 years ago

Hi @rjjrbatarao

Thanks for your nice words and the enhancement request.

I already found out and fixed the issue, and will release a new version within today. It won't reconnect if already connected, certainly after verifying the same host and port.

Even though your issue is a good one, I almost ignored it because the issue was opened without MRE. Luckily, I changed my mind before pressing the button.

Hopefully you'll do it correctly next time.

Best Regards,

khoih-prog commented 2 years ago

This is the test debug showing no more connect attempt to the same host:port


Starting AsyncHTTPSRequest_ESP using ESP32_DEV
AsyncTCP_SSL v1.3.1
AsyncHTTPSRequest_Generic v2.1.2
Connecting to WiFi SSID: HueNet1
...
AsyncHTTPSRequest @ IP : 192.168.2.80
[AHTTPS] open: connecting to hostname = worldtimeapi.org:443    <====== New connect attempt
[AHTTPS] _client->connecting to worldtimeapi.org , 443
[AHTTPS] client.connect OK to worldtimeapi.org , 443

**************************************
[AHTTPS] Response Code =  HTTP OK

**************************************
abbreviation: EDT
client_ip: 104.247.247.31
datetime: 2022-10-18T13:10:03.030242-04:00
day_of_week: 2
day_of_year: 291
dst: true
dst_from: 2022-03-13T07:00:00+00:00
dst_offset: 3600
dst_until: 2022-11-06T06:00:00+00:00
raw_offset: -18000
timezone: America/Toronto
unixtime: 1666113003
utc_datetime: 2022-10-18T17:10:03.030242+00:00
utc_offset: -04:00
week_number: 42
**************************************
HH[AHTTPS] open: already connected    <====== No more connect attempt
H
**************************************
[AHTTPS] Response Code =  HTTP OK

**************************************
abbreviation: EDT
client_ip: 104.247.247.31
datetime: 2022-10-18T13:10:31.897109-04:00
day_of_week: 2
day_of_year: 291
dst: true
dst_from: 2022-03-13T07:00:00+00:00
dst_offset: 3600
dst_until: 2022-11-06T06:00:00+00:00
raw_offset: -18000
timezone: America/Toronto
unixtime: 1666113031
utc_datetime: 2022-10-18T17:10:31.897109+00:00
utc_offset: -04:00
week_number: 42
khoih-prog commented 2 years ago

Hi @rjjrbatarao

The new AsyncHTTPSRequest_Generic v2.1.3 has just been released. Your contribution is noted in Contributions and Thanks.

Please test and report any more issue or enhancement.

Best Regards,


Releases v2.1.3

  1. Not try to reconnect to the same host:port after connected. Check setReuse feature #12
rjjrbatarao commented 2 years ago

Wow thank you very much for the feature your the Man!, I'll definitely will follow the MRE next time, I'll test it with my current code and report how it goes.