v1.10.0 to fix bug and clean-up

### Releases v1.10.0

1. Fix bug.
2. Clean up
This commit is contained in:
Khoi Hoang
2022-10-20 16:54:51 -04:00
committed by GitHub
parent 89079c915e
commit 89d10346df
20 changed files with 359 additions and 358 deletions
+97 -58
View File
@@ -18,7 +18,7 @@
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.9.2
Version: 1.10.0
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -32,6 +32,7 @@
1.9.0 K Hoang 30/08/2022 Fix bug. Improve debug messages. Optimize code
1.9.1 K Hoang 09/09/2022 Fix ESP32 chipID for example `AsyncHTTPRequest_ESP_WiFiManager`
1.9.2 K Hoang 18/10/2022 Not try to reconnect to the same host:port after connected
1.10.0 K Hoang 20/10/2022 Fix bug. Clean up
*****************************************************************************************************************************/
#pragma once
@@ -39,18 +40,24 @@
#ifndef ASYNC_HTTP_REQUEST_GENERIC_HPP
#define ASYNC_HTTP_REQUEST_GENERIC_HPP
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION "AsyncHTTPRequest_Generic v1.9.2"
////////////////////////////////////////
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION "AsyncHTTPRequest_Generic v1.10.0"
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MAJOR 1
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MINOR 9
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_PATCH 2
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MINOR 10
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_PATCH 0
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT 1009002
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT 1010000
////////////////////////////////////////
#include <Arduino.h>
#include "AsyncHTTPRequest_Debug_Generic.h"
////////////////////////////////////////
#ifndef DEBUG_IOTA_PORT
#define DEBUG_IOTA_PORT Serial
#endif
@@ -61,11 +68,20 @@
#define DEBUG_IOTA_HTTP_SET false
#endif
////////////////////////////////////////
// KH add
#define SAFE_DELETE(object) if (object) { delete object;}
#define SAFE_DELETE_ARRAY(object) if (object) { delete[] object;}
#define ASYNC_HTTP_PREFIX "HTTP://"
#define ASYNC_HTTP_PORT 80
#define ASYNC_HTTPS_PREFIX "HTTPS://"
#define ASYNC_HTTPS_PORT 443
////////////////////////////////////////
#if ESP32
#include <AsyncTCP.h>
@@ -87,9 +103,9 @@
#define _AHTTP_lock
#define _AHTTP_unlock
#elif ( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \
defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \
defined(STM32WB) || defined(STM32MP1) )
#elif ( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || \
defined(STM32F7) || defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) || \
defined(STM32G0) || defined(STM32G4) || defined(STM32WB) || defined(STM32MP1) )
#include "STM32AsyncTCP.h"
@@ -100,10 +116,12 @@
#endif
////////////////////////////////////////
#include <pgmspace.h>
// Merge xbuf
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////
struct xseg
{
@@ -111,6 +129,8 @@ struct xseg
uint8_t data[];
};
////////////////////////////////////////
class xbuf: public Print
{
public:
@@ -204,7 +224,7 @@ class xbuf: public Print
};
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////
#define DEBUG_HTTP(format,...) if(_debug){\
DEBUG_IOTA_PORT.printf("Debug(%3ld): ", millis()-_requestStartTime);\
@@ -212,6 +232,8 @@ class xbuf: public Print
#define DEFAULT_RX_TIMEOUT 3 // Seconds for timeout
////////////////////////////////////////
#define HTTPCODE_CONNECTION_REFUSED (-1)
#define HTTPCODE_SEND_HEADER_FAILED (-2)
#define HTTPCODE_SEND_PAYLOAD_FAILED (-3)
@@ -224,6 +246,8 @@ class xbuf: public Print
#define HTTPCODE_STREAM_WRITE (-10)
#define HTTPCODE_TIMEOUT (-11)
////////////////////////////////////////
typedef enum
{
readyStateUnsent = 0, // Client created, open not yet called
@@ -232,62 +256,68 @@ typedef enum
readyStateLoading = 3, // receiving, partial data available
readyStateDone = 4 // Request complete, all data available.
} reqStates;
////////////////////////////////////////
class AsyncHTTPRequest
{
struct header
struct header
{
header* next;
char* name;
char* value;
header(): next(nullptr), name(nullptr), value(nullptr)
{};
~header()
{
header* next;
char* name;
char* value;
header(): next(nullptr), name(nullptr), value(nullptr)
{};
~header()
{
SAFE_DELETE_ARRAY(name)
SAFE_DELETE_ARRAY(value)
SAFE_DELETE(next)
//delete[] name;
//delete[] value;
//delete next;
}
};
SAFE_DELETE_ARRAY(name)
SAFE_DELETE_ARRAY(value)
SAFE_DELETE(next)
//delete[] name;
//delete[] value;
//delete next;
}
};
struct URL
{
char *buffer;
char *scheme;
char *host;
int port;
char *path;
char *query;
char *buffer;
char *scheme;
char *host;
int port;
char *path;
char *query;
URL(): buffer(nullptr), scheme(nullptr), host(nullptr),
port(80), path(nullptr), query(nullptr)
{};
URL(): buffer(nullptr), scheme(nullptr), host(nullptr),
port(80), path(nullptr), query(nullptr)
{};
~URL()
{
SAFE_DELETE_ARRAY(buffer)
SAFE_DELETE_ARRAY(scheme)
SAFE_DELETE_ARRAY(host)
SAFE_DELETE_ARRAY(path)
SAFE_DELETE_ARRAY(query)
}
};
typedef std::function<void(void*, AsyncHTTPRequest*, int readyState)> readyStateChangeCB;
typedef std::function<void(void*, AsyncHTTPRequest*, size_t available)> onDataCB;
~URL()
{
SAFE_DELETE_ARRAY(buffer)
SAFE_DELETE_ARRAY(scheme)
SAFE_DELETE_ARRAY(host)
SAFE_DELETE_ARRAY(path)
SAFE_DELETE_ARRAY(query)
}
};
typedef std::function<void(void*, AsyncHTTPRequest*, int readyState)> readyStateChangeCB;
typedef std::function<void(void*, AsyncHTTPRequest*, size_t available)> onDataCB;
////////////////////////////////////////
public:
AsyncHTTPRequest();
~AsyncHTTPRequest();
//External functions in typical order of use:
//__________________________________________________________________________________________________________*/
////////////////////////////////////////
void setDebug(bool); // Turn debug message on/off
bool debug(); // is debug on or off?
@@ -341,16 +371,23 @@ class AsyncHTTPRequest
size_t responseRead(uint8_t* buffer, size_t len); // Read response into buffer
uint32_t elapsedTime(); // Elapsed time of in progress transaction or last completed (ms)
String version(); // Version of AsyncHTTPRequest
//___________________________________________________________________________________________________________________________________
////////////////////////////////////////
private:
// New in v1.1.1
bool _requestReadyToSend;
//////
// New in v1.1.0
typedef enum { HTTPmethodGET, HTTPmethodPOST, HTTPmethodPUT, HTTPmethodPATCH, HTTPmethodDELETE, HTTPmethodHEAD, HTTPmethodMAX } HTTPmethod;
typedef enum
{
HTTPmethodGET,
HTTPmethodPOST,
HTTPmethodPUT,
HTTPmethodPATCH,
HTTPmethodDELETE,
HTTPmethodHEAD,
HTTPmethodMAX
} HTTPmethod;
HTTPmethod _HTTPmethod;
@@ -415,4 +452,6 @@ class AsyncHTTPRequest
bool _collectHeaders();
};
////////////////////////////////////////
#endif // ASYNC_HTTP_REQUEST_GENERIC_HPP