Merge pull request #13816 from s-hadinger/webquery_https

Add HTTPS support to `WebQuery` and `WebGetConfig` (ESP32x only)
This commit is contained in:
s-hadinger 2021-11-26 19:37:39 +01:00 committed by GitHub
commit f79934bd8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -15,6 +15,7 @@ All notable changes to this project will be documented in this file.
- Command ``IfxPeriod `` to overrule ``Teleperiod`` for Influx messages (#13750) - Command ``IfxPeriod `` to overrule ``Teleperiod`` for Influx messages (#13750)
- OTA over HTTPS (ESP32x only) - OTA over HTTPS (ESP32x only)
- Berry add ``import re`` regex module - Berry add ``import re`` regex module
- Add HTTPS support to ``WebQuery`` (ESP32x only)
### Changed ### Changed
- ESP8266 Gratuitous ARP enabled and set to 60 seconds (#13623) - ESP8266 Gratuitous ARP enabled and set to 60 seconds (#13623)

View File

@ -3117,8 +3117,12 @@ int WebQuery(char *buffer)
// An unlimited number of headers can be sent per request, and a body can be sent for all command types // An unlimited number of headers can be sent per request, and a body can be sent for all command types
// The body will be ignored if sending a GET command // The body will be ignored if sending a GET command
#if defined(ESP32) && defined(USE_WEBCLIENT_HTTPS)
HTTPClientLight http;
#else // HTTP only
WiFiClient http_client; WiFiClient http_client;
HTTPClient http; HTTPClient http;
#endif
int status = WEBCMND_WRONG_PARAMETERS; int status = WEBCMND_WRONG_PARAMETERS;
@ -3127,7 +3131,11 @@ int WebQuery(char *buffer)
char *method = strtok_r(temp, " ", &temp); char *method = strtok_r(temp, " ", &temp);
if (url && method) { if (url && method) {
#if defined(ESP32) && defined(USE_WEBCLIENT_HTTPS)
if (http.begin(UrlEncode(url))) {
#else // HTTP only
if (http.begin(http_client, UrlEncode(url))) { if (http.begin(http_client, UrlEncode(url))) {
#endif
char empty_body[1] = { 0 }; char empty_body[1] = { 0 };
char *body = empty_body; char *body = empty_body;
if (temp) { // There is a body and/or header if (temp) { // There is a body and/or header
@ -3204,9 +3212,15 @@ int WebGetConfig(char *buffer)
DEBUG_CORE_LOG(PSTR("WEB: Config Uri '%s'"), url.c_str()); DEBUG_CORE_LOG(PSTR("WEB: Config Uri '%s'"), url.c_str());
#if defined(ESP32) && defined(USE_WEBCLIENT_HTTPS)
HTTPClientLight http;
if (http.begin(UrlEncode(url))) { // UrlEncode(url) = |http://192.168.178.86/cm?cmnd=POWER1%20ON|
#else // HTTP only
WiFiClient http_client; WiFiClient http_client;
HTTPClient http; HTTPClient http;
if (http.begin(http_client, UrlEncode(url))) { // UrlEncode(url) = |http://192.168.178.86/cm?cmnd=POWER1%20ON| if (http.begin(http_client, UrlEncode(url))) { // UrlEncode(url) = |http://192.168.178.86/cm?cmnd=POWER1%20ON|
#endif
int http_code = http.GET(); // Start connection and send HTTP header int http_code = http.GET(); // Start connection and send HTTP header
if (http_code > 0) { // http_code will be negative on error if (http_code > 0) { // http_code will be negative on error
status = WEBCMND_DONE; status = WEBCMND_DONE;