From 233dbbbbcdf505c54b3fd7c6234366a1859d11c0 Mon Sep 17 00:00:00 2001
From: Khoi Hoang <57012152+khoih-prog@users.noreply.github.com>
Date: Wed, 23 Dec 2020 23:35:07 -0500
Subject: [PATCH] v1.1.1
### Releases v1.1.1
1. Prevent crash if request and/or method not correct.
---
README.md | 10 +++
.../AsyncCustomHeader_STM32.ino | 21 ++++-
.../AsyncDweetGet_STM32.ino | 22 ++++-
.../AsyncDweetPost_STM32.ino | 22 ++++-
.../AsyncHTTPRequest_ESP.ino | 20 ++++-
.../AsyncHTTPRequest_ESP_WiFiManager.ino | 24 ++++-
.../AsyncHTTPRequest_STM32.ino | 24 ++++-
.../AsyncSimpleGET_STM32.ino | 22 ++++-
.../AsyncWebClientRepeating_STM32.ino | 21 ++++-
library.json | 2 +-
library.properties | 2 +-
src/AsyncHTTPRequest_Debug_Generic.h | 3 +-
src/AsyncHTTPRequest_Generic.h | 11 ++-
src/AsyncHTTPRequest_Impl_Generic.h | 88 +++++++++++++++---
src/utility/xbuf.h | 3 +-
src/utility/xbuf_Impl.h | 3 +-
src_cpp/AsyncHTTPRequest_Debug_Generic.h | 3 +-
src_cpp/AsyncHTTPRequest_Generic.cpp | 89 ++++++++++++++++---
src_cpp/AsyncHTTPRequest_Generic.h | 13 ++-
src_cpp/utility/xbuf.cpp | 4 +-
src_cpp/utility/xbuf.h | 3 +-
src_h/AsyncHTTPRequest_Debug_Generic.h | 3 +-
src_h/AsyncHTTPRequest_Generic.h | 11 ++-
src_h/AsyncHTTPRequest_Impl_Generic.h | 88 +++++++++++++++---
src_h/utility/xbuf.h | 3 +-
src_h/utility/xbuf_Impl.h | 3 +-
26 files changed, 432 insertions(+), 86 deletions(-)
diff --git a/README.md b/README.md
index f1b462d..07495fd 100644
--- a/README.md
+++ b/README.md
@@ -17,6 +17,7 @@
* [Supports](#supports)
* [Principles of operation](#principles-of-operation)
* [Changelog](#changelog)
+ * [Releases v1.1.1](#releases-v111)
* [Releases v1.1.0](#releases-v110)
* [Releases v1.0.2](#releases-v102)
* [Releases v1.0.1](#releases-v101)
@@ -104,6 +105,11 @@ Chunked responses are recognized and handled transparently.
## Changelog
+### Releases v1.1.1
+
+1. Prevent crash if request and/or method not correct.
+
+
### Releases v1.1.0
1. Add HTTP PUT, PATCH, DELETE and HEAD methods. Check [Add support for sending PUT, PATCH, DELETE request](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/issues/5)
@@ -836,6 +842,10 @@ Submit issues to: [AsyncHTTPRequest_Generic issues](https://github.com/khoih-pro
## Releases
+### Releases v1.1.1
+
+1. Prevent crash if request and/or method not correct.
+
### Releases v1.1.0
1. Add HTTP PUT, PATCH, DELETE and HEAD methods. Check [Add support for sending PUT, PATCH, DELETE request](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/issues/5)
diff --git a/examples/AsyncCustomHeader_STM32/AsyncCustomHeader_STM32.ino b/examples/AsyncCustomHeader_STM32/AsyncCustomHeader_STM32.ino
index b13f5cb..79dbde9 100644
--- a/examples/AsyncCustomHeader_STM32/AsyncCustomHeader_STM32.ino
+++ b/examples/AsyncCustomHeader_STM32/AsyncCustomHeader_STM32.ino
@@ -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 .
- Version: 1.1.0
+ Version: 1.1.1
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -25,6 +25,7 @@
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
+ 1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
*****************************************************************************************************************************/
#include "defines.h"
@@ -49,13 +50,27 @@ Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS);
void sendRequest(void)
{
+ static bool requestOpenResult;
+
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
{
Serial.println("\nSending GET Request to " + String(GET_ServerAddress));
- request.open("GET", GET_ServerAddress);
+ requestOpenResult = request.open("GET", GET_ServerAddress);
//request.setReqHeader("X-CUSTOM-HEADER", "custom_value");
- request.send();
+ if (requestOpenResult)
+ {
+ // Only send() if open() returns true, or crash
+ request.send();
+ }
+ else
+ {
+ Serial.println("Can't send bad request");
+ }
+ }
+ else
+ {
+ Serial.println("Can't send request");
}
}
diff --git a/examples/AsyncDweetGet_STM32/AsyncDweetGet_STM32.ino b/examples/AsyncDweetGet_STM32/AsyncDweetGet_STM32.ino
index f44643a..90094ea 100644
--- a/examples/AsyncDweetGet_STM32/AsyncDweetGet_STM32.ino
+++ b/examples/AsyncDweetGet_STM32/AsyncDweetGet_STM32.ino
@@ -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 .
- Version: 1.1.0
+ Version: 1.1.1
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -25,6 +25,7 @@
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
+ 1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
*****************************************************************************************************************************/
/**
@@ -60,10 +61,25 @@ Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS);
void sendRequest(void)
{
+ static bool requestOpenResult;
+
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
{
- request.open("GET", (GET_ServerAddress + dweetName + String(millis()/1000)).c_str() );
- request.send();
+ requestOpenResult = request.open("GET", (GET_ServerAddress + dweetName + String(millis()/1000)).c_str() );
+
+ if (requestOpenResult)
+ {
+ // Only send() if open() returns true, or crash
+ request.send();
+ }
+ else
+ {
+ Serial.println("Can't send bad request");
+ }
+ }
+ else
+ {
+ Serial.println("Can't send request");
}
}
diff --git a/examples/AsyncDweetPost_STM32/AsyncDweetPost_STM32.ino b/examples/AsyncDweetPost_STM32/AsyncDweetPost_STM32.ino
index d1f2555..d7f6ba8 100644
--- a/examples/AsyncDweetPost_STM32/AsyncDweetPost_STM32.ino
+++ b/examples/AsyncDweetPost_STM32/AsyncDweetPost_STM32.ino
@@ -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 .
- Version: 1.1.0
+ Version: 1.1.1
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -25,6 +25,7 @@
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
+ 1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
*****************************************************************************************************************************/
// Dweet.io POST client. Connects to dweet.io once every ten seconds, sends a POST request and a request body.
@@ -54,6 +55,8 @@ Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS);
void sendRequest(void)
{
+ static bool requestOpenResult;
+
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
{
String postData = "sensorValue=";
@@ -61,8 +64,21 @@ void sendRequest(void)
Serial.println("\nMaking new POST request");
- request.open("POST", (POST_ServerAddress + dweetName + postData).c_str() );
- request.send();
+ requestOpenResult = request.open("POST", (POST_ServerAddress + dweetName + postData).c_str() );
+
+ if (requestOpenResult)
+ {
+ // Only send() if open() returns true, or crash
+ request.send();
+ }
+ else
+ {
+ Serial.println("Can't send bad request");
+ }
+ }
+ else
+ {
+ Serial.println("Can't send request");
}
}
diff --git a/examples/AsyncHTTPRequest_ESP/AsyncHTTPRequest_ESP.ino b/examples/AsyncHTTPRequest_ESP/AsyncHTTPRequest_ESP.ino
index b6eb516..bd89637 100644
--- a/examples/AsyncHTTPRequest_ESP/AsyncHTTPRequest_ESP.ino
+++ b/examples/AsyncHTTPRequest_ESP/AsyncHTTPRequest_ESP.ino
@@ -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 .
- Version: 1.1.0
+ Version: 1.1.1
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -25,6 +25,7 @@
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
+ 1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
*****************************************************************************************************************************/
//************************************************************************************************************
//
@@ -103,11 +104,22 @@ void heartBeatPrint(void)
void sendRequest()
{
+ static bool requestOpenResult;
+
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
{
- //request.open("GET", "http://worldtimeapi.org/api/timezone/Europe/London.txt");
- request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt");
- request.send();
+ //requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/Europe/London.txt");
+ requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt");
+
+ if (requestOpenResult)
+ {
+ // Only send() if open() returns true, or crash
+ request.send();
+ }
+ else
+ {
+ Serial.println("Can't send bad request");
+ }
}
else
{
diff --git a/examples/AsyncHTTPRequest_ESP_WiFiManager/AsyncHTTPRequest_ESP_WiFiManager.ino b/examples/AsyncHTTPRequest_ESP_WiFiManager/AsyncHTTPRequest_ESP_WiFiManager.ino
index a2197ca..96f999a 100644
--- a/examples/AsyncHTTPRequest_ESP_WiFiManager/AsyncHTTPRequest_ESP_WiFiManager.ino
+++ b/examples/AsyncHTTPRequest_ESP_WiFiManager/AsyncHTTPRequest_ESP_WiFiManager.ino
@@ -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 .
- Version: 1.1.0
+ Version: 1.1.1
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -25,6 +25,7 @@
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
+ 1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
*****************************************************************************************************************************/
//************************************************************************************************************
//
@@ -488,11 +489,26 @@ void saveConfigData()
void sendRequest()
{
+ static bool requestOpenResult;
+
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
{
- //request.open("GET", "http://worldtimeapi.org/api/timezone/Europe/London.txt");
- request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt");
- request.send();
+ //requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/Europe/London.txt");
+ requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt");
+
+ if (requestOpenResult)
+ {
+ // Only send() if open() returns true, or crash
+ request.send();
+ }
+ else
+ {
+ Serial.println("Can't send bad request");
+ }
+ }
+ else
+ {
+ Serial.println("Can't send request");
}
}
diff --git a/examples/AsyncHTTPRequest_STM32/AsyncHTTPRequest_STM32.ino b/examples/AsyncHTTPRequest_STM32/AsyncHTTPRequest_STM32.ino
index 9e1ae0e..dd09a79 100644
--- a/examples/AsyncHTTPRequest_STM32/AsyncHTTPRequest_STM32.ino
+++ b/examples/AsyncHTTPRequest_STM32/AsyncHTTPRequest_STM32.ino
@@ -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 .
- Version: 1.1.0
+ Version: 1.1.1
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -25,6 +25,7 @@
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
+ 1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
*****************************************************************************************************************************/
//************************************************************************************************************
//
@@ -67,11 +68,26 @@ Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS);
void sendRequest(void)
{
+ static bool requestOpenResult;
+
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
{
- //request.open("GET", "http://worldtimeapi.org/api/timezone/Europe/London.txt");
- request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt");
- request.send();
+ //requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/Europe/London.txt");
+ requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt");
+
+ if (requestOpenResult)
+ {
+ // Only send() if open() returns true, or crash
+ request.send();
+ }
+ else
+ {
+ Serial.println("Can't send bad request");
+ }
+ }
+ else
+ {
+ Serial.println("Can't send request");
}
}
diff --git a/examples/AsyncSimpleGET_STM32/AsyncSimpleGET_STM32.ino b/examples/AsyncSimpleGET_STM32/AsyncSimpleGET_STM32.ino
index c9a0c1c..94a2752 100644
--- a/examples/AsyncSimpleGET_STM32/AsyncSimpleGET_STM32.ino
+++ b/examples/AsyncSimpleGET_STM32/AsyncSimpleGET_STM32.ino
@@ -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 .
- Version: 1.1.0
+ Version: 1.1.1
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -25,6 +25,7 @@
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
+ 1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
*****************************************************************************************************************************/
#include "defines.h"
@@ -49,10 +50,25 @@ Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS);
void sendRequest(void)
{
+ static bool requestOpenResult;
+
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
{
- request.open("GET", GET_ServerAddress);
- request.send();
+ requestOpenResult = request.open("GET", GET_ServerAddress);
+
+ if (requestOpenResult)
+ {
+ // Only send() if open() returns true, or crash
+ request.send();
+ }
+ else
+ {
+ Serial.println("Can't send bad request");
+ }
+ }
+ else
+ {
+ Serial.println("Can't send request");
}
}
diff --git a/examples/AsyncWebClientRepeating_STM32/AsyncWebClientRepeating_STM32.ino b/examples/AsyncWebClientRepeating_STM32/AsyncWebClientRepeating_STM32.ino
index 4fbeac9..a7c3c0c 100644
--- a/examples/AsyncWebClientRepeating_STM32/AsyncWebClientRepeating_STM32.ino
+++ b/examples/AsyncWebClientRepeating_STM32/AsyncWebClientRepeating_STM32.ino
@@ -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 .
- Version: 1.1.0
+ Version: 1.1.1
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -25,6 +25,7 @@
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
+ 1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
*****************************************************************************************************************************/
#include "defines.h"
@@ -51,11 +52,25 @@ Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS);
void sendRequest(void)
{
+ static bool requestOpenResult;
+
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
{
- request.open("GET", (GET_ServerAddress + GET_Location).c_str());
+ requestOpenResult = request.open("GET", (GET_ServerAddress + GET_Location).c_str());
- request.send();
+ if (requestOpenResult)
+ {
+ // Only send() if open() returns true, or crash
+ request.send();
+ }
+ else
+ {
+ Serial.println("Can't send bad request");
+ }
+ }
+ else
+ {
+ Serial.println("Can't send request");
}
}
diff --git a/library.json b/library.json
index 663e084..c8fd0c0 100644
--- a/library.json
+++ b/library.json
@@ -1,6 +1,6 @@
{
"name":"AsyncHTTPRequest_Generic",
- "version": "1.1.0",
+ "version": "1.1.1",
"description":"Simple Async HTTP Request library, supporting GET, POST, PUT, PATCH, DELETE and HEAD, on top of AsyncTCP libraries, such as AsyncTCP, ESPAsyncTCP, AsyncTCP_STM32, etc.. for ESP32, ESP8266 and currently STM32 with built-in LAN8742A Ethernet.",
"keywords":"async,tcp,http,ESP8266,ESP32,ESPAsyncTCP,AsyncTCP,stm32,ethernet,wifi,lan8742a",
"authors": [
diff --git a/library.properties b/library.properties
index 80ac8a3..4d6f8e9 100644
--- a/library.properties
+++ b/library.properties
@@ -1,5 +1,5 @@
name=AsyncHTTPRequest_Generic
-version=1.1.0
+version=1.1.1
author=Bob Lemaire,Khoi Hoang
maintainer=Khoi Hoang
license=MIT
diff --git a/src/AsyncHTTPRequest_Debug_Generic.h b/src/AsyncHTTPRequest_Debug_Generic.h
index 2de2102..4645730 100644
--- a/src/AsyncHTTPRequest_Debug_Generic.h
+++ b/src/AsyncHTTPRequest_Debug_Generic.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 .
- Version: 1.1.0
+ Version: 1.1.1
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -25,6 +25,7 @@
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
+ 1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
*****************************************************************************************************************************/
#pragma once
diff --git a/src/AsyncHTTPRequest_Generic.h b/src/AsyncHTTPRequest_Generic.h
index eb32d73..1c38092 100644
--- a/src/AsyncHTTPRequest_Generic.h
+++ b/src/AsyncHTTPRequest_Generic.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 .
- Version: 1.1.0
+ Version: 1.1.1
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -25,11 +25,12 @@
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
+ 1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
*****************************************************************************************************************************/
#pragma once
-#define ASYNC_HTTP_REQUEST_GENERIC_VERSION "AsyncHTTPRequest_Generic v1.1.0"
+#define ASYNC_HTTP_REQUEST_GENERIC_VERSION "AsyncHTTPRequest_Generic v1.1.1"
#include
@@ -226,6 +227,10 @@ class AsyncHTTPRequest
private:
+ // New in v1.1.1
+ bool _requestReadyToSend;
+ //////
+
// New in v1.1.0
typedef enum { HTTPmethodGET, HTTPmethodPOST, HTTPmethodPUT, HTTPmethodPATCH, HTTPmethodDELETE, HTTPmethodHEAD, HTTPmethodMAX } HTTPmethod;
@@ -234,7 +239,7 @@ class AsyncHTTPRequest
const char* _HTTPmethodStringwithSpace[HTTPmethodMAX] = {"GET ", "POST ", "PUT ", "PATCH ", "DELETE ", "HEAD "};
//////
- reqStates _readyState;
+ reqStates _readyState;
int16_t _HTTPcode; // HTTP response code or (negative) exception code
bool _chunked; // Processing chunked response
diff --git a/src/AsyncHTTPRequest_Impl_Generic.h b/src/AsyncHTTPRequest_Impl_Generic.h
index 57cc74d..dece218 100644
--- a/src/AsyncHTTPRequest_Impl_Generic.h
+++ b/src/AsyncHTTPRequest_Impl_Generic.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 .
- Version: 1.1.0
+ Version: 1.1.1
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -25,10 +25,12 @@
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
+ 1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
*****************************************************************************************************************************/
#pragma once
+#define CANT_SEND_BAD_REQUEST F("Can't send() bad request")
//**************************************************************************************************************
AsyncHTTPRequest::AsyncHTTPRequest(): _readyState(readyStateUnsent), _HTTPcode(0), _chunked(false), _debug(DEBUG_IOTA_HTTP_SET)
@@ -110,7 +112,10 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL)
_chunked = false;
_contentRead = 0;
_readyState = readyStateUnsent;
-
+
+ // New in v1.1.1
+ _requestReadyToSend = false;
+ //////
if (strcmp(method, "GET") == 0)
{
@@ -139,13 +144,16 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL)
}
//////
else
+ {
return false;
+ }
if (!_parseURL(URL))
{
return false;
}
+
if ( _client && _client->connected() && (strcmp(_URL->host, _connectedHost) != 0 || _URL->port != _connectedPort))
{
return false;
@@ -161,6 +169,10 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL)
SAFE_DELETE_ARRAY(hostName)
_lastActivity = millis();
+
+ // New in v1.1.1
+ _requestReadyToSend = true;
+ //////
return _connect();
}
@@ -184,8 +196,18 @@ void AsyncHTTPRequest::setTimeout(int seconds)
//**************************************************************************************************************
bool AsyncHTTPRequest::send()
-{
- AHTTP_LOGDEBUG("send()");
+{
+ // New in v1.1.1
+ if (_requestReadyToSend)
+ {
+ AHTTP_LOGDEBUG("send()");
+ }
+ else
+ {
+ AHTTP_LOGDEBUG(CANT_SEND_BAD_REQUEST);
+ return false;
+ }
+ //////
MUTEX_LOCK(false)
@@ -202,7 +224,17 @@ bool AsyncHTTPRequest::send()
//**************************************************************************************************************
bool AsyncHTTPRequest::send(String body)
{
- AHTTP_LOGDEBUG3("send(String)", body.substring(0, 16).c_str(), ", length =", body.length());
+ // New in v1.1.1
+ if (_requestReadyToSend)
+ {
+ AHTTP_LOGDEBUG3("send(String)", body.substring(0, 16).c_str(), ", length =", body.length());
+ }
+ else
+ {
+ AHTTP_LOGDEBUG(CANT_SEND_BAD_REQUEST);
+ return false;
+ }
+ //////
MUTEX_LOCK(false)
@@ -226,7 +258,17 @@ bool AsyncHTTPRequest::send(String body)
//**************************************************************************************************************
bool AsyncHTTPRequest::send(const char* body)
{
- AHTTP_LOGDEBUG3("send(char)", body, ", length =", strlen(body));
+ // New in v1.1.1
+ if (_requestReadyToSend)
+ {
+ AHTTP_LOGDEBUG3("send(char)", body, ", length =", strlen(body));
+ }
+ else
+ {
+ AHTTP_LOGDEBUG(CANT_SEND_BAD_REQUEST);
+ return false;
+ }
+ //////
MUTEX_LOCK(false)
@@ -250,7 +292,17 @@ bool AsyncHTTPRequest::send(const char* body)
//**************************************************************************************************************
bool AsyncHTTPRequest::send(const uint8_t* body, size_t len)
{
- AHTTP_LOGDEBUG3("send(char)", (char*) body, ", length =", len);
+ // New in v1.1.1
+ if (_requestReadyToSend)
+ {
+ AHTTP_LOGDEBUG3("send(char)", (char*) body, ", length =", len);
+ }
+ else
+ {
+ AHTTP_LOGDEBUG(CANT_SEND_BAD_REQUEST);
+ return false;
+ }
+ //////
MUTEX_LOCK(false)
@@ -274,7 +326,17 @@ bool AsyncHTTPRequest::send(const uint8_t* body, size_t len)
//**************************************************************************************************************
bool AsyncHTTPRequest::send(xbuf* body, size_t len)
{
- AHTTP_LOGDEBUG3("send(char)", body->peekString(16).c_str(), ", length =", len);
+ // New in v1.1.1
+ if (_requestReadyToSend)
+ {
+ AHTTP_LOGDEBUG3("send(char)", body->peekString(16).c_str(), ", length =", len);
+ }
+ else
+ {
+ AHTTP_LOGDEBUG(CANT_SEND_BAD_REQUEST);
+ return false;
+ }
+ //////
MUTEX_LOCK(false)
@@ -610,6 +672,10 @@ bool AsyncHTTPRequest::_buildRequest()
return false;
}
+ // New in v1.1.1
+ AHTTP_LOGDEBUG1("_HTTPmethod =", _HTTPmethod);
+ AHTTP_LOGDEBUG3(_HTTPmethodStringwithSpace[_HTTPmethod], _URL->path, _URL->query, " HTTP/1.1\r\n" );
+ //////
// New in v1.1.0
_request->write(_HTTPmethodStringwithSpace[_HTTPmethod]);
@@ -618,11 +684,7 @@ bool AsyncHTTPRequest::_buildRequest()
_request->write(_URL->path);
_request->write(_URL->query);
_request->write(" HTTP/1.1\r\n");
-
- // New in v1.1.0
- AHTTP_LOGDEBUG3(_HTTPmethodStringwithSpace[_HTTPmethod], _URL->path, _URL->query, " HTTP/1.1\r\n" );
- //////
-
+
SAFE_DELETE(_URL)
_URL = nullptr;
diff --git a/src/utility/xbuf.h b/src/utility/xbuf.h
index 658eddf..412c724 100644
--- a/src/utility/xbuf.h
+++ b/src/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 .
- Version: 1.1.0
+ Version: 1.1.1
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -25,6 +25,7 @@
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
+ 1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
*****************************************************************************************************************************/
/********************************************************************************************
diff --git a/src/utility/xbuf_Impl.h b/src/utility/xbuf_Impl.h
index 91527fc..36638e7 100644
--- a/src/utility/xbuf_Impl.h
+++ b/src/utility/xbuf_Impl.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 .
- Version: 1.1.0
+ Version: 1.1.1
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -25,6 +25,7 @@
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
+ 1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
*****************************************************************************************************************************/
#pragma once
diff --git a/src_cpp/AsyncHTTPRequest_Debug_Generic.h b/src_cpp/AsyncHTTPRequest_Debug_Generic.h
index 2de2102..4645730 100644
--- a/src_cpp/AsyncHTTPRequest_Debug_Generic.h
+++ b/src_cpp/AsyncHTTPRequest_Debug_Generic.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 .
- Version: 1.1.0
+ Version: 1.1.1
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -25,6 +25,7 @@
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
+ 1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
*****************************************************************************************************************************/
#pragma once
diff --git a/src_cpp/AsyncHTTPRequest_Generic.cpp b/src_cpp/AsyncHTTPRequest_Generic.cpp
index 78678a2..b0d0ea4 100644
--- a/src_cpp/AsyncHTTPRequest_Generic.cpp
+++ b/src_cpp/AsyncHTTPRequest_Generic.cpp
@@ -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 .
- Version: 1.1.0
+ Version: 1.1.1
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -25,12 +25,15 @@
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
+ 1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
*****************************************************************************************************************************/
#include "AsyncHTTPRequest_Debug_Generic.h"
#include "AsyncHTTPRequest_Generic.h"
+#define CANT_SEND_BAD_REQUEST F("Can't send() bad request")
+
//**************************************************************************************************************
AsyncHTTPRequest::AsyncHTTPRequest(): _readyState(readyStateUnsent), _HTTPcode(0), _chunked(false), _debug(DEBUG_IOTA_HTTP_SET)
, _timeout(DEFAULT_RX_TIMEOUT), _lastActivity(0), _requestStartTime(0), _requestEndTime(0), _URL(nullptr)
@@ -111,7 +114,10 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL)
_chunked = false;
_contentRead = 0;
_readyState = readyStateUnsent;
-
+
+ // New in v1.1.1
+ _requestReadyToSend = false;
+ //////
if (strcmp(method, "GET") == 0)
{
@@ -140,13 +146,16 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL)
}
//////
else
+ {
return false;
+ }
if (!_parseURL(URL))
{
return false;
}
+
if ( _client && _client->connected() && (strcmp(_URL->host, _connectedHost) != 0 || _URL->port != _connectedPort))
{
return false;
@@ -162,6 +171,10 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL)
SAFE_DELETE_ARRAY(hostName)
_lastActivity = millis();
+
+ // New in v1.1.1
+ _requestReadyToSend = true;
+ //////
return _connect();
}
@@ -185,8 +198,18 @@ void AsyncHTTPRequest::setTimeout(int seconds)
//**************************************************************************************************************
bool AsyncHTTPRequest::send()
-{
- AHTTP_LOGDEBUG("send()");
+{
+ // New in v1.1.1
+ if (_requestReadyToSend)
+ {
+ AHTTP_LOGDEBUG("send()");
+ }
+ else
+ {
+ AHTTP_LOGDEBUG(CANT_SEND_BAD_REQUEST);
+ return false;
+ }
+ //////
MUTEX_LOCK(false)
@@ -203,7 +226,17 @@ bool AsyncHTTPRequest::send()
//**************************************************************************************************************
bool AsyncHTTPRequest::send(String body)
{
- AHTTP_LOGDEBUG3("send(String)", body.substring(0, 16).c_str(), ", length =", body.length());
+ // New in v1.1.1
+ if (_requestReadyToSend)
+ {
+ AHTTP_LOGDEBUG3("send(String)", body.substring(0, 16).c_str(), ", length =", body.length());
+ }
+ else
+ {
+ AHTTP_LOGDEBUG(CANT_SEND_BAD_REQUEST);
+ return false;
+ }
+ //////
MUTEX_LOCK(false)
@@ -227,7 +260,17 @@ bool AsyncHTTPRequest::send(String body)
//**************************************************************************************************************
bool AsyncHTTPRequest::send(const char* body)
{
- AHTTP_LOGDEBUG3("send(char)", body, ", length =", strlen(body));
+ // New in v1.1.1
+ if (_requestReadyToSend)
+ {
+ AHTTP_LOGDEBUG3("send(char)", body, ", length =", strlen(body));
+ }
+ else
+ {
+ AHTTP_LOGDEBUG(CANT_SEND_BAD_REQUEST);
+ return false;
+ }
+ //////
MUTEX_LOCK(false)
@@ -251,7 +294,17 @@ bool AsyncHTTPRequest::send(const char* body)
//**************************************************************************************************************
bool AsyncHTTPRequest::send(const uint8_t* body, size_t len)
{
- AHTTP_LOGDEBUG3("send(char)", (char*) body, ", length =", len);
+ // New in v1.1.1
+ if (_requestReadyToSend)
+ {
+ AHTTP_LOGDEBUG3("send(char)", (char*) body, ", length =", len);
+ }
+ else
+ {
+ AHTTP_LOGDEBUG(CANT_SEND_BAD_REQUEST);
+ return false;
+ }
+ //////
MUTEX_LOCK(false)
@@ -275,7 +328,17 @@ bool AsyncHTTPRequest::send(const uint8_t* body, size_t len)
//**************************************************************************************************************
bool AsyncHTTPRequest::send(xbuf* body, size_t len)
{
- AHTTP_LOGDEBUG3("send(char)", body->peekString(16).c_str(), ", length =", len);
+ // New in v1.1.1
+ if (_requestReadyToSend)
+ {
+ AHTTP_LOGDEBUG3("send(char)", body->peekString(16).c_str(), ", length =", len);
+ }
+ else
+ {
+ AHTTP_LOGDEBUG(CANT_SEND_BAD_REQUEST);
+ return false;
+ }
+ //////
MUTEX_LOCK(false)
@@ -611,6 +674,10 @@ bool AsyncHTTPRequest::_buildRequest()
return false;
}
+ // New in v1.1.1
+ AHTTP_LOGDEBUG1("_HTTPmethod =", _HTTPmethod);
+ AHTTP_LOGDEBUG3(_HTTPmethodStringwithSpace[_HTTPmethod], _URL->path, _URL->query, " HTTP/1.1\r\n" );
+ //////
// New in v1.1.0
_request->write(_HTTPmethodStringwithSpace[_HTTPmethod]);
@@ -619,11 +686,7 @@ bool AsyncHTTPRequest::_buildRequest()
_request->write(_URL->path);
_request->write(_URL->query);
_request->write(" HTTP/1.1\r\n");
-
- // New in v1.1.0
- AHTTP_LOGDEBUG3(_HTTPmethodStringwithSpace[_HTTPmethod], _URL->path, _URL->query, " HTTP/1.1\r\n" );
- //////
-
+
SAFE_DELETE(_URL)
_URL = nullptr;
diff --git a/src_cpp/AsyncHTTPRequest_Generic.h b/src_cpp/AsyncHTTPRequest_Generic.h
index b7bd314..ed351a7 100644
--- a/src_cpp/AsyncHTTPRequest_Generic.h
+++ b/src_cpp/AsyncHTTPRequest_Generic.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 .
- Version: 1.1.0
+ Version: 1.1.1
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -25,11 +25,12 @@
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
+ 1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
*****************************************************************************************************************************/
#pragma once
-#define ASYNC_HTTP_REQUEST_GENERIC_VERSION "AsyncHTTPRequest_Generic v1.1.0"
+#define ASYNC_HTTP_REQUEST_GENERIC_VERSION "AsyncHTTPRequest_Generic v1.1.1"
#include
@@ -226,6 +227,10 @@ class AsyncHTTPRequest
private:
+ // New in v1.1.1
+ bool _requestReadyToSend;
+ //////
+
// New in v1.1.0
typedef enum { HTTPmethodGET, HTTPmethodPOST, HTTPmethodPUT, HTTPmethodPATCH, HTTPmethodDELETE, HTTPmethodHEAD, HTTPmethodMAX } HTTPmethod;
@@ -234,7 +239,7 @@ class AsyncHTTPRequest
const char* _HTTPmethodStringwithSpace[HTTPmethodMAX] = {"GET ", "POST ", "PUT ", "PATCH ", "DELETE ", "HEAD "};
//////
- reqStates _readyState;
+ reqStates _readyState;
int16_t _HTTPcode; // HTTP response code or (negative) exception code
bool _chunked; // Processing chunked response
@@ -293,3 +298,5 @@ class AsyncHTTPRequest
};
+
+
diff --git a/src_cpp/utility/xbuf.cpp b/src_cpp/utility/xbuf.cpp
index aa49426..1d9e45b 100644
--- a/src_cpp/utility/xbuf.cpp
+++ b/src_cpp/utility/xbuf.cpp
@@ -17,13 +17,15 @@
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 .
- Version: 1.0.2
+ Version: 1.1.1
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
+ 1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
+ 1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
*****************************************************************************************************************************/
#include "utility/xbuf.h"
diff --git a/src_cpp/utility/xbuf.h b/src_cpp/utility/xbuf.h
index 658eddf..412c724 100644
--- a/src_cpp/utility/xbuf.h
+++ b/src_cpp/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 .
- Version: 1.1.0
+ Version: 1.1.1
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -25,6 +25,7 @@
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
+ 1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
*****************************************************************************************************************************/
/********************************************************************************************
diff --git a/src_h/AsyncHTTPRequest_Debug_Generic.h b/src_h/AsyncHTTPRequest_Debug_Generic.h
index 2de2102..4645730 100644
--- a/src_h/AsyncHTTPRequest_Debug_Generic.h
+++ b/src_h/AsyncHTTPRequest_Debug_Generic.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 .
- Version: 1.1.0
+ Version: 1.1.1
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -25,6 +25,7 @@
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
+ 1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
*****************************************************************************************************************************/
#pragma once
diff --git a/src_h/AsyncHTTPRequest_Generic.h b/src_h/AsyncHTTPRequest_Generic.h
index eb32d73..1c38092 100644
--- a/src_h/AsyncHTTPRequest_Generic.h
+++ b/src_h/AsyncHTTPRequest_Generic.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 .
- Version: 1.1.0
+ Version: 1.1.1
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -25,11 +25,12 @@
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
+ 1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
*****************************************************************************************************************************/
#pragma once
-#define ASYNC_HTTP_REQUEST_GENERIC_VERSION "AsyncHTTPRequest_Generic v1.1.0"
+#define ASYNC_HTTP_REQUEST_GENERIC_VERSION "AsyncHTTPRequest_Generic v1.1.1"
#include
@@ -226,6 +227,10 @@ class AsyncHTTPRequest
private:
+ // New in v1.1.1
+ bool _requestReadyToSend;
+ //////
+
// New in v1.1.0
typedef enum { HTTPmethodGET, HTTPmethodPOST, HTTPmethodPUT, HTTPmethodPATCH, HTTPmethodDELETE, HTTPmethodHEAD, HTTPmethodMAX } HTTPmethod;
@@ -234,7 +239,7 @@ class AsyncHTTPRequest
const char* _HTTPmethodStringwithSpace[HTTPmethodMAX] = {"GET ", "POST ", "PUT ", "PATCH ", "DELETE ", "HEAD "};
//////
- reqStates _readyState;
+ reqStates _readyState;
int16_t _HTTPcode; // HTTP response code or (negative) exception code
bool _chunked; // Processing chunked response
diff --git a/src_h/AsyncHTTPRequest_Impl_Generic.h b/src_h/AsyncHTTPRequest_Impl_Generic.h
index 57cc74d..dece218 100644
--- a/src_h/AsyncHTTPRequest_Impl_Generic.h
+++ b/src_h/AsyncHTTPRequest_Impl_Generic.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 .
- Version: 1.1.0
+ Version: 1.1.1
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -25,10 +25,12 @@
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
+ 1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
*****************************************************************************************************************************/
#pragma once
+#define CANT_SEND_BAD_REQUEST F("Can't send() bad request")
//**************************************************************************************************************
AsyncHTTPRequest::AsyncHTTPRequest(): _readyState(readyStateUnsent), _HTTPcode(0), _chunked(false), _debug(DEBUG_IOTA_HTTP_SET)
@@ -110,7 +112,10 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL)
_chunked = false;
_contentRead = 0;
_readyState = readyStateUnsent;
-
+
+ // New in v1.1.1
+ _requestReadyToSend = false;
+ //////
if (strcmp(method, "GET") == 0)
{
@@ -139,13 +144,16 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL)
}
//////
else
+ {
return false;
+ }
if (!_parseURL(URL))
{
return false;
}
+
if ( _client && _client->connected() && (strcmp(_URL->host, _connectedHost) != 0 || _URL->port != _connectedPort))
{
return false;
@@ -161,6 +169,10 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL)
SAFE_DELETE_ARRAY(hostName)
_lastActivity = millis();
+
+ // New in v1.1.1
+ _requestReadyToSend = true;
+ //////
return _connect();
}
@@ -184,8 +196,18 @@ void AsyncHTTPRequest::setTimeout(int seconds)
//**************************************************************************************************************
bool AsyncHTTPRequest::send()
-{
- AHTTP_LOGDEBUG("send()");
+{
+ // New in v1.1.1
+ if (_requestReadyToSend)
+ {
+ AHTTP_LOGDEBUG("send()");
+ }
+ else
+ {
+ AHTTP_LOGDEBUG(CANT_SEND_BAD_REQUEST);
+ return false;
+ }
+ //////
MUTEX_LOCK(false)
@@ -202,7 +224,17 @@ bool AsyncHTTPRequest::send()
//**************************************************************************************************************
bool AsyncHTTPRequest::send(String body)
{
- AHTTP_LOGDEBUG3("send(String)", body.substring(0, 16).c_str(), ", length =", body.length());
+ // New in v1.1.1
+ if (_requestReadyToSend)
+ {
+ AHTTP_LOGDEBUG3("send(String)", body.substring(0, 16).c_str(), ", length =", body.length());
+ }
+ else
+ {
+ AHTTP_LOGDEBUG(CANT_SEND_BAD_REQUEST);
+ return false;
+ }
+ //////
MUTEX_LOCK(false)
@@ -226,7 +258,17 @@ bool AsyncHTTPRequest::send(String body)
//**************************************************************************************************************
bool AsyncHTTPRequest::send(const char* body)
{
- AHTTP_LOGDEBUG3("send(char)", body, ", length =", strlen(body));
+ // New in v1.1.1
+ if (_requestReadyToSend)
+ {
+ AHTTP_LOGDEBUG3("send(char)", body, ", length =", strlen(body));
+ }
+ else
+ {
+ AHTTP_LOGDEBUG(CANT_SEND_BAD_REQUEST);
+ return false;
+ }
+ //////
MUTEX_LOCK(false)
@@ -250,7 +292,17 @@ bool AsyncHTTPRequest::send(const char* body)
//**************************************************************************************************************
bool AsyncHTTPRequest::send(const uint8_t* body, size_t len)
{
- AHTTP_LOGDEBUG3("send(char)", (char*) body, ", length =", len);
+ // New in v1.1.1
+ if (_requestReadyToSend)
+ {
+ AHTTP_LOGDEBUG3("send(char)", (char*) body, ", length =", len);
+ }
+ else
+ {
+ AHTTP_LOGDEBUG(CANT_SEND_BAD_REQUEST);
+ return false;
+ }
+ //////
MUTEX_LOCK(false)
@@ -274,7 +326,17 @@ bool AsyncHTTPRequest::send(const uint8_t* body, size_t len)
//**************************************************************************************************************
bool AsyncHTTPRequest::send(xbuf* body, size_t len)
{
- AHTTP_LOGDEBUG3("send(char)", body->peekString(16).c_str(), ", length =", len);
+ // New in v1.1.1
+ if (_requestReadyToSend)
+ {
+ AHTTP_LOGDEBUG3("send(char)", body->peekString(16).c_str(), ", length =", len);
+ }
+ else
+ {
+ AHTTP_LOGDEBUG(CANT_SEND_BAD_REQUEST);
+ return false;
+ }
+ //////
MUTEX_LOCK(false)
@@ -610,6 +672,10 @@ bool AsyncHTTPRequest::_buildRequest()
return false;
}
+ // New in v1.1.1
+ AHTTP_LOGDEBUG1("_HTTPmethod =", _HTTPmethod);
+ AHTTP_LOGDEBUG3(_HTTPmethodStringwithSpace[_HTTPmethod], _URL->path, _URL->query, " HTTP/1.1\r\n" );
+ //////
// New in v1.1.0
_request->write(_HTTPmethodStringwithSpace[_HTTPmethod]);
@@ -618,11 +684,7 @@ bool AsyncHTTPRequest::_buildRequest()
_request->write(_URL->path);
_request->write(_URL->query);
_request->write(" HTTP/1.1\r\n");
-
- // New in v1.1.0
- AHTTP_LOGDEBUG3(_HTTPmethodStringwithSpace[_HTTPmethod], _URL->path, _URL->query, " HTTP/1.1\r\n" );
- //////
-
+
SAFE_DELETE(_URL)
_URL = nullptr;
diff --git a/src_h/utility/xbuf.h b/src_h/utility/xbuf.h
index 658eddf..412c724 100644
--- a/src_h/utility/xbuf.h
+++ b/src_h/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 .
- Version: 1.1.0
+ Version: 1.1.1
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -25,6 +25,7 @@
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
+ 1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
*****************************************************************************************************************************/
/********************************************************************************************
diff --git a/src_h/utility/xbuf_Impl.h b/src_h/utility/xbuf_Impl.h
index 91527fc..36638e7 100644
--- a/src_h/utility/xbuf_Impl.h
+++ b/src_h/utility/xbuf_Impl.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 .
- Version: 1.1.0
+ Version: 1.1.1
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -25,6 +25,7 @@
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
+ 1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
*****************************************************************************************************************************/
#pragma once