### Releases v1.1.1

1. Prevent crash if request and/or method not correct.
This commit is contained in:
Khoi Hoang
2020-12-23 23:35:07 -05:00
committed by GitHub
parent c11a245270
commit 233dbbbbcd
26 changed files with 432 additions and 86 deletions

View File

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

View File

@@ -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.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");
}
}

View File

@@ -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.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");
}
}

View File

@@ -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.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");
}
}

View File

@@ -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.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
{

View File

@@ -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.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");
}
}

View File

@@ -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.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");
}
}

View File

@@ -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.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");
}
}

View File

@@ -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.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");
}
}

View File

@@ -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": [

View File

@@ -1,5 +1,5 @@
name=AsyncHTTPRequest_Generic
version=1.1.0
version=1.1.1
author=Bob Lemaire,Khoi Hoang <khoih.prog@gmail.com>
maintainer=Khoi Hoang <khoih.prog@gmail.com>
license=MIT

View File

@@ -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.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

View File

@@ -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.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 <Arduino.h>
@@ -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

View File

@@ -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.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;

View File

@@ -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.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.
*****************************************************************************************************************************/
/********************************************************************************************

View File

@@ -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.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

View File

@@ -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.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

View File

@@ -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.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;

View File

@@ -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.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 <Arduino.h>
@@ -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
};

View File

@@ -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 <https://www.gnu.org/licenses/>.
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"

View File

@@ -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.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.
*****************************************************************************************************************************/
/********************************************************************************************

View File

@@ -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.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

View File

@@ -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.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 <Arduino.h>
@@ -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

View File

@@ -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.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;

View File

@@ -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.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.
*****************************************************************************************************************************/
/********************************************************************************************

View File

@@ -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.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