mirror of
https://github.com/khoih-prog/AsyncHTTPRequest_Generic.git
synced 2026-01-26 17:12:37 +01:00
v1.1.1
### Releases v1.1.1 1. Prevent crash if request and/or method not correct.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user