forked from khoih-prog/AsyncHTTPRequest_Generic
v1.4.0 to fix crashing bug
### Releases v1.4.0 1. Fix crashing bug when request a non-existing IP. Check [Http GET polling causes crash when host disconnected #22](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/issues/22) 2. Modify `platform.ini` to avoid compile error with PIO when using ESP8266/ESP32
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Version: 1.3.1
|
||||
Version: 1.4.0
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
@@ -33,6 +33,7 @@
|
||||
1.2.0 K Hoang 11/04/2021 Add support to LAN8720 using STM32F4 or STM32F7
|
||||
1.3.0 K Hoang 09/07/2021 Add support to WT32_ETH01 (ESP32 + LAN8720) boards
|
||||
1.3.1 K Hoang 09/10/2021 Update `platform.ini` and `library.json`
|
||||
1.4.0 K Hoang 23/11/2021 Fix crashing bug when request a non-existing IP
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Version: 1.3.1
|
||||
Version: 1.4.0
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
@@ -33,6 +33,7 @@
|
||||
1.2.0 K Hoang 11/04/2021 Add support to LAN8720 using STM32F4 or STM32F7
|
||||
1.3.0 K Hoang 09/07/2021 Add support to WT32_ETH01 (ESP32 + LAN8720) boards
|
||||
1.3.1 K Hoang 09/10/2021 Update `platform.ini` and `library.json`
|
||||
1.4.0 K Hoang 23/11/2021 Fix crashing bug when request a non-existing IP
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#include "AsyncHTTPRequest_Debug_Generic.h"
|
||||
@@ -183,6 +184,8 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL)
|
||||
sprintf(hostName, "%s:%d", _URL->host, _URL->port);
|
||||
_addHeader("host", hostName);
|
||||
|
||||
AHTTP_LOGDEBUG1("open: conneting to hostname =", hostName);
|
||||
|
||||
SAFE_DELETE_ARRAY(hostName)
|
||||
|
||||
_lastActivity = millis();
|
||||
@@ -191,8 +194,6 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL)
|
||||
_requestReadyToSend = true;
|
||||
//////
|
||||
|
||||
AHTTP_LOGDEBUG1("open: conneting to hostname =", hostName);
|
||||
|
||||
return _connect();
|
||||
}
|
||||
else
|
||||
@@ -258,9 +259,13 @@ bool AsyncHTTPRequest::send(String body)
|
||||
return false;
|
||||
}
|
||||
//////
|
||||
|
||||
AHTTP_LOGERROR1("01) send String body =", body);
|
||||
|
||||
MUTEX_LOCK(false)
|
||||
|
||||
AHTTP_LOGERROR1("02) send String body =", body);
|
||||
|
||||
_addHeader("Content-Length", String(body.length()).c_str());
|
||||
|
||||
if ( ! _buildRequest())
|
||||
@@ -270,9 +275,15 @@ bool AsyncHTTPRequest::send(String body)
|
||||
return false;
|
||||
}
|
||||
|
||||
AHTTP_LOGERROR1("1) send String body =", body);
|
||||
|
||||
_request->write(body);
|
||||
|
||||
AHTTP_LOGERROR1("2) send String body =", body);
|
||||
_send();
|
||||
|
||||
AHTTP_LOGERROR1("3) send String body =", body);
|
||||
|
||||
_AHTTP_unlock;
|
||||
|
||||
return true;
|
||||
@@ -789,12 +800,27 @@ size_t AsyncHTTPRequest::_send()
|
||||
|
||||
AHTTP_LOGDEBUG1("_send(), _request->available =", _request->available());
|
||||
|
||||
#if 1
|
||||
if ( ! _client->connected())
|
||||
{
|
||||
AHTTP_LOGDEBUG("!connected");
|
||||
|
||||
return 0;
|
||||
}
|
||||
else if ( ! _client->canSend())
|
||||
{
|
||||
AHTTP_LOGDEBUG("*can't send");
|
||||
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
if ( ! _client->connected() || ! _client->canSend())
|
||||
{
|
||||
AHTTP_LOGDEBUG("*can't send");
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
size_t supply = _request->available();
|
||||
size_t demand = _client->space();
|
||||
@@ -1008,17 +1034,17 @@ void AsyncHTTPRequest::_onDisconnect(AsyncClient* client)
|
||||
|
||||
if (_readyState < readyStateOpened)
|
||||
{
|
||||
AHTTP_LOGDEBUG("HTTPCODE_NOT_CONNECTED");
|
||||
_HTTPcode = HTTPCODE_NOT_CONNECTED;
|
||||
}
|
||||
else if (_HTTPcode > 0 &&
|
||||
(_readyState < readyStateHdrsRecvd || (_contentRead + _response->available()) < _contentLength))
|
||||
{
|
||||
AHTTP_LOGDEBUG("HTTPCODE_CONNECTION_LOST");
|
||||
_HTTPcode = HTTPCODE_CONNECTION_LOST;
|
||||
}
|
||||
|
||||
SAFE_DELETE(_client)
|
||||
|
||||
_client = nullptr;
|
||||
AHTTP_LOGDEBUG1("_HTTPcode = ", _HTTPcode);
|
||||
|
||||
SAFE_DELETE_ARRAY(_connectedHost)
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Version: 1.3.1
|
||||
Version: 1.4.0
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
@@ -33,6 +33,7 @@
|
||||
1.2.0 K Hoang 11/04/2021 Add support to LAN8720 using STM32F4 or STM32F7
|
||||
1.3.0 K Hoang 09/07/2021 Add support to WT32_ETH01 (ESP32 + LAN8720) boards
|
||||
1.3.1 K Hoang 09/10/2021 Update `platform.ini` and `library.json`
|
||||
1.4.0 K Hoang 23/11/2021 Fix crashing bug when request a non-existing IP
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
@@ -40,7 +41,7 @@
|
||||
#ifndef ASYNC_HTTP_REQUEST_GENERIC_H
|
||||
#define ASYNC_HTTP_REQUEST_GENERIC_H
|
||||
|
||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION "AsyncHTTPRequest_Generic v1.3.0"
|
||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION "AsyncHTTPRequest_Generic v1.4.0"
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Version: 1.3.1
|
||||
Version: 1.4.0
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
@@ -33,6 +33,7 @@
|
||||
1.2.0 K Hoang 11/04/2021 Add support to LAN8720 using STM32F4 or STM32F7
|
||||
1.3.0 K Hoang 09/07/2021 Add support to WT32_ETH01 (ESP32 + LAN8720) boards
|
||||
1.3.1 K Hoang 09/10/2021 Update `platform.ini` and `library.json`
|
||||
1.4.0 K Hoang 23/11/2021 Fix crashing bug when request a non-existing IP
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#include "utility/xbuf.h"
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Version: 1.3.1
|
||||
Version: 1.4.0
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
@@ -33,6 +33,7 @@
|
||||
1.2.0 K Hoang 11/04/2021 Add support to LAN8720 using STM32F4 or STM32F7
|
||||
1.3.0 K Hoang 09/07/2021 Add support to WT32_ETH01 (ESP32 + LAN8720) boards
|
||||
1.3.1 K Hoang 09/10/2021 Update `platform.ini` and `library.json`
|
||||
1.4.0 K Hoang 23/11/2021 Fix crashing bug when request a non-existing IP
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
/********************************************************************************************
|
||||
|
||||
Reference in New Issue
Block a user