### 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,14 +50,28 @@ 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");
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");
}
}
void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)

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,11 +61,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", (GET_ServerAddress + dweetName + String(millis()/1000)).c_str() );
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");
}
}
void parseResponse(String responseText)

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,9 +64,22 @@ void sendRequest(void)
Serial.println("\nMaking new POST request");
request.open("POST", (POST_ServerAddress + dweetName + postData).c_str() );
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");
}
}
void parseResponse(String responseText)

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,13 +104,24 @@ 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");
//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.
*****************************************************************************************************************************/
//************************************************************************************************************
//
@@ -488,12 +489,27 @@ 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");
//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");
}
}
void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)

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,12 +68,27 @@ 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");
//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");
}
}
void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)

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,11 +50,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", GET_ServerAddress);
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");
}
}
void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)

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,12 +52,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", (GET_ServerAddress + GET_Location).c_str());
requestOpenResult = request.open("GET", (GET_ServerAddress + GET_Location).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");
}
}
void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)

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;

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)
@@ -111,6 +113,9 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL)
_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;
@@ -162,6 +170,10 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL)
_lastActivity = millis();
// New in v1.1.1
_requestReadyToSend = true;
//////
return _connect();
}
else
@@ -184,8 +196,18 @@ void AsyncHTTPRequest::setTimeout(int seconds)
//**************************************************************************************************************
bool AsyncHTTPRequest::send()
{
// New in v1.1.1
if (_requestReadyToSend)
{
AHTTP_LOGDEBUG("send()");
}
else
{
AHTTP_LOGDEBUG(CANT_SEND_BAD_REQUEST);
return false;
}
//////
MUTEX_LOCK(false)
@@ -201,8 +223,18 @@ bool AsyncHTTPRequest::send()
//**************************************************************************************************************
bool AsyncHTTPRequest::send(String body)
{
// 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)
@@ -225,8 +257,18 @@ bool AsyncHTTPRequest::send(String body)
//**************************************************************************************************************
bool AsyncHTTPRequest::send(const char* 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)
@@ -249,8 +291,18 @@ bool AsyncHTTPRequest::send(const char* body)
//**************************************************************************************************************
bool AsyncHTTPRequest::send(const uint8_t* body, size_t 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)
@@ -273,8 +325,18 @@ bool AsyncHTTPRequest::send(const uint8_t* body, size_t len)
//**************************************************************************************************************
bool AsyncHTTPRequest::send(xbuf* body, size_t 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]);
@@ -619,10 +685,6 @@ bool AsyncHTTPRequest::_buildRequest()
_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)
@@ -112,6 +115,9 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL)
_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;
@@ -163,6 +172,10 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL)
_lastActivity = millis();
// New in v1.1.1
_requestReadyToSend = true;
//////
return _connect();
}
else
@@ -185,8 +198,18 @@ void AsyncHTTPRequest::setTimeout(int seconds)
//**************************************************************************************************************
bool AsyncHTTPRequest::send()
{
// New in v1.1.1
if (_requestReadyToSend)
{
AHTTP_LOGDEBUG("send()");
}
else
{
AHTTP_LOGDEBUG(CANT_SEND_BAD_REQUEST);
return false;
}
//////
MUTEX_LOCK(false)
@@ -202,8 +225,18 @@ bool AsyncHTTPRequest::send()
//**************************************************************************************************************
bool AsyncHTTPRequest::send(String body)
{
// 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,8 +259,18 @@ bool AsyncHTTPRequest::send(String body)
//**************************************************************************************************************
bool AsyncHTTPRequest::send(const char* 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,8 +293,18 @@ bool AsyncHTTPRequest::send(const char* body)
//**************************************************************************************************************
bool AsyncHTTPRequest::send(const uint8_t* body, size_t 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,8 +327,18 @@ bool AsyncHTTPRequest::send(const uint8_t* body, size_t len)
//**************************************************************************************************************
bool AsyncHTTPRequest::send(xbuf* body, size_t 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]);
@@ -620,10 +687,6 @@ bool AsyncHTTPRequest::_buildRequest()
_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;
@@ -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;

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)
@@ -111,6 +113,9 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL)
_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;
@@ -162,6 +170,10 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL)
_lastActivity = millis();
// New in v1.1.1
_requestReadyToSend = true;
//////
return _connect();
}
else
@@ -184,8 +196,18 @@ void AsyncHTTPRequest::setTimeout(int seconds)
//**************************************************************************************************************
bool AsyncHTTPRequest::send()
{
// New in v1.1.1
if (_requestReadyToSend)
{
AHTTP_LOGDEBUG("send()");
}
else
{
AHTTP_LOGDEBUG(CANT_SEND_BAD_REQUEST);
return false;
}
//////
MUTEX_LOCK(false)
@@ -201,8 +223,18 @@ bool AsyncHTTPRequest::send()
//**************************************************************************************************************
bool AsyncHTTPRequest::send(String body)
{
// 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)
@@ -225,8 +257,18 @@ bool AsyncHTTPRequest::send(String body)
//**************************************************************************************************************
bool AsyncHTTPRequest::send(const char* 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)
@@ -249,8 +291,18 @@ bool AsyncHTTPRequest::send(const char* body)
//**************************************************************************************************************
bool AsyncHTTPRequest::send(const uint8_t* body, size_t 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)
@@ -273,8 +325,18 @@ bool AsyncHTTPRequest::send(const uint8_t* body, size_t len)
//**************************************************************************************************************
bool AsyncHTTPRequest::send(xbuf* body, size_t 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]);
@@ -619,10 +685,6 @@ bool AsyncHTTPRequest::_buildRequest()
_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