Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Commit 233dbbb

Browse files
authored
v1.1.1
### Releases v1.1.1 1. Prevent crash if request and/or method not correct.
1 parent c11a245 commit 233dbbb

26 files changed

+432
-86
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* [Supports](#supports)
1818
* [Principles of operation](#principles-of-operation)
1919
* [Changelog](#changelog)
20+
* [Releases v1.1.1](#releases-v111)
2021
* [Releases v1.1.0](#releases-v110)
2122
* [Releases v1.0.2](#releases-v102)
2223
* [Releases v1.0.1](#releases-v101)
@@ -104,6 +105,11 @@ Chunked responses are recognized and handled transparently.
104105

105106
## Changelog
106107

108+
### Releases v1.1.1
109+
110+
1. Prevent crash if request and/or method not correct.
111+
112+
107113
### Releases v1.1.0
108114

109115
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
836842

837843
## Releases
838844

845+
### Releases v1.1.1
846+
847+
1. Prevent crash if request and/or method not correct.
848+
839849
### Releases v1.1.0
840850

841851
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)

examples/AsyncCustomHeader_STM32/AsyncCustomHeader_STM32.ino

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
1818
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
1919
20-
Version: 1.1.0
20+
Version: 1.1.1
2121
2222
Version Modified By Date Comments
2323
------- ----------- ---------- -----------
2424
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
2525
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
2626
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
2727
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
28+
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
2829
*****************************************************************************************************************************/
2930

3031
#include "defines.h"
@@ -49,13 +50,27 @@ Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS);
4950

5051
void sendRequest(void)
5152
{
53+
static bool requestOpenResult;
54+
5255
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
5356
{
5457
Serial.println("\nSending GET Request to " + String(GET_ServerAddress));
5558

56-
request.open("GET", GET_ServerAddress);
59+
requestOpenResult = request.open("GET", GET_ServerAddress);
5760
//request.setReqHeader("X-CUSTOM-HEADER", "custom_value");
58-
request.send();
61+
if (requestOpenResult)
62+
{
63+
// Only send() if open() returns true, or crash
64+
request.send();
65+
}
66+
else
67+
{
68+
Serial.println("Can't send bad request");
69+
}
70+
}
71+
else
72+
{
73+
Serial.println("Can't send request");
5974
}
6075
}
6176

examples/AsyncDweetGet_STM32/AsyncDweetGet_STM32.ino

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
1818
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
1919
20-
Version: 1.1.0
20+
Version: 1.1.1
2121
2222
Version Modified By Date Comments
2323
------- ----------- ---------- -----------
2424
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
2525
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
2626
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
2727
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
28+
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
2829
*****************************************************************************************************************************/
2930

3031
/**
@@ -60,10 +61,25 @@ Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS);
6061

6162
void sendRequest(void)
6263
{
64+
static bool requestOpenResult;
65+
6366
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
6467
{
65-
request.open("GET", (GET_ServerAddress + dweetName + String(millis()/1000)).c_str() );
66-
request.send();
68+
requestOpenResult = request.open("GET", (GET_ServerAddress + dweetName + String(millis()/1000)).c_str() );
69+
70+
if (requestOpenResult)
71+
{
72+
// Only send() if open() returns true, or crash
73+
request.send();
74+
}
75+
else
76+
{
77+
Serial.println("Can't send bad request");
78+
}
79+
}
80+
else
81+
{
82+
Serial.println("Can't send request");
6783
}
6884
}
6985

examples/AsyncDweetPost_STM32/AsyncDweetPost_STM32.ino

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
1818
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
1919
20-
Version: 1.1.0
20+
Version: 1.1.1
2121
2222
Version Modified By Date Comments
2323
------- ----------- ---------- -----------
2424
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
2525
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
2626
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
2727
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
28+
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
2829
*****************************************************************************************************************************/
2930

3031
// Dweet.io POST client. Connects to dweet.io once every ten seconds, sends a POST request and a request body.
@@ -54,15 +55,30 @@ Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS);
5455

5556
void sendRequest(void)
5657
{
58+
static bool requestOpenResult;
59+
5760
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
5861
{
5962
String postData = "sensorValue=";
6063
postData += analogRead(A0);
6164

6265
Serial.println("\nMaking new POST request");
6366

64-
request.open("POST", (POST_ServerAddress + dweetName + postData).c_str() );
65-
request.send();
67+
requestOpenResult = request.open("POST", (POST_ServerAddress + dweetName + postData).c_str() );
68+
69+
if (requestOpenResult)
70+
{
71+
// Only send() if open() returns true, or crash
72+
request.send();
73+
}
74+
else
75+
{
76+
Serial.println("Can't send bad request");
77+
}
78+
}
79+
else
80+
{
81+
Serial.println("Can't send request");
6682
}
6783
}
6884

examples/AsyncHTTPRequest_ESP/AsyncHTTPRequest_ESP.ino

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
1818
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
1919
20-
Version: 1.1.0
20+
Version: 1.1.1
2121
2222
Version Modified By Date Comments
2323
------- ----------- ---------- -----------
2424
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
2525
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
2626
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
2727
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
28+
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
2829
*****************************************************************************************************************************/
2930
//************************************************************************************************************
3031
//
@@ -103,11 +104,22 @@ void heartBeatPrint(void)
103104

104105
void sendRequest()
105106
{
107+
static bool requestOpenResult;
108+
106109
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
107110
{
108-
//request.open("GET", "http://worldtimeapi.org/api/timezone/Europe/London.txt");
109-
request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt");
110-
request.send();
111+
//requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/Europe/London.txt");
112+
requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt");
113+
114+
if (requestOpenResult)
115+
{
116+
// Only send() if open() returns true, or crash
117+
request.send();
118+
}
119+
else
120+
{
121+
Serial.println("Can't send bad request");
122+
}
111123
}
112124
else
113125
{

examples/AsyncHTTPRequest_ESP_WiFiManager/AsyncHTTPRequest_ESP_WiFiManager.ino

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
1818
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
1919
20-
Version: 1.1.0
20+
Version: 1.1.1
2121
2222
Version Modified By Date Comments
2323
------- ----------- ---------- -----------
2424
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
2525
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
2626
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
2727
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
28+
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
2829
*****************************************************************************************************************************/
2930
//************************************************************************************************************
3031
//
@@ -488,11 +489,26 @@ void saveConfigData()
488489

489490
void sendRequest()
490491
{
492+
static bool requestOpenResult;
493+
491494
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
492495
{
493-
//request.open("GET", "http://worldtimeapi.org/api/timezone/Europe/London.txt");
494-
request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt");
495-
request.send();
496+
//requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/Europe/London.txt");
497+
requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt");
498+
499+
if (requestOpenResult)
500+
{
501+
// Only send() if open() returns true, or crash
502+
request.send();
503+
}
504+
else
505+
{
506+
Serial.println("Can't send bad request");
507+
}
508+
}
509+
else
510+
{
511+
Serial.println("Can't send request");
496512
}
497513
}
498514

examples/AsyncHTTPRequest_STM32/AsyncHTTPRequest_STM32.ino

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
1818
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
1919
20-
Version: 1.1.0
20+
Version: 1.1.1
2121
2222
Version Modified By Date Comments
2323
------- ----------- ---------- -----------
2424
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
2525
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
2626
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
2727
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
28+
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
2829
*****************************************************************************************************************************/
2930
//************************************************************************************************************
3031
//
@@ -67,11 +68,26 @@ Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS);
6768

6869
void sendRequest(void)
6970
{
71+
static bool requestOpenResult;
72+
7073
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
7174
{
72-
//request.open("GET", "http://worldtimeapi.org/api/timezone/Europe/London.txt");
73-
request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt");
74-
request.send();
75+
//requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/Europe/London.txt");
76+
requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt");
77+
78+
if (requestOpenResult)
79+
{
80+
// Only send() if open() returns true, or crash
81+
request.send();
82+
}
83+
else
84+
{
85+
Serial.println("Can't send bad request");
86+
}
87+
}
88+
else
89+
{
90+
Serial.println("Can't send request");
7591
}
7692
}
7793

examples/AsyncSimpleGET_STM32/AsyncSimpleGET_STM32.ino

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
1818
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
1919
20-
Version: 1.1.0
20+
Version: 1.1.1
2121
2222
Version Modified By Date Comments
2323
------- ----------- ---------- -----------
2424
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
2525
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
2626
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
2727
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
28+
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
2829
*****************************************************************************************************************************/
2930

3031
#include "defines.h"
@@ -49,10 +50,25 @@ Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS);
4950

5051
void sendRequest(void)
5152
{
53+
static bool requestOpenResult;
54+
5255
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
5356
{
54-
request.open("GET", GET_ServerAddress);
55-
request.send();
57+
requestOpenResult = request.open("GET", GET_ServerAddress);
58+
59+
if (requestOpenResult)
60+
{
61+
// Only send() if open() returns true, or crash
62+
request.send();
63+
}
64+
else
65+
{
66+
Serial.println("Can't send bad request");
67+
}
68+
}
69+
else
70+
{
71+
Serial.println("Can't send request");
5672
}
5773
}
5874

examples/AsyncWebClientRepeating_STM32/AsyncWebClientRepeating_STM32.ino

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
1818
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
1919
20-
Version: 1.1.0
20+
Version: 1.1.1
2121
2222
Version Modified By Date Comments
2323
------- ----------- ---------- -----------
2424
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
2525
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
2626
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
2727
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
28+
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
2829
*****************************************************************************************************************************/
2930

3031
#include "defines.h"
@@ -51,11 +52,25 @@ Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS);
5152

5253
void sendRequest(void)
5354
{
55+
static bool requestOpenResult;
56+
5457
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
5558
{
56-
request.open("GET", (GET_ServerAddress + GET_Location).c_str());
59+
requestOpenResult = request.open("GET", (GET_ServerAddress + GET_Location).c_str());
5760

58-
request.send();
61+
if (requestOpenResult)
62+
{
63+
// Only send() if open() returns true, or crash
64+
request.send();
65+
}
66+
else
67+
{
68+
Serial.println("Can't send bad request");
69+
}
70+
}
71+
else
72+
{
73+
Serial.println("Can't send request");
5974
}
6075
}
6176

0 commit comments

Comments
 (0)