From d261fa35f57cd620907bb050b1cbe7b8aff98fbb Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Tue, 3 Jan 2017 16:20:03 -0500 Subject: [PATCH] Add support for PATCH operations --- keywords.txt | 1 + src/HttpClient.cpp | 25 +++++++++++++++++++++++++ src/HttpClient.h | 19 +++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/keywords.txt b/keywords.txt index f62ba70..7c2061c 100644 --- a/keywords.txt +++ b/keywords.txt @@ -17,6 +17,7 @@ WebSocketClient KEYWORD1 get KEYWORD2 post KEYWORD2 put KEYWORD2 +patch KEYWORD2 startRequest KEYWORD2 beginRequest KEYWORD2 sendHeader KEYWORD2 diff --git a/src/HttpClient.cpp b/src/HttpClient.cpp index e66d488..f3accc3 100644 --- a/src/HttpClient.cpp +++ b/src/HttpClient.cpp @@ -332,6 +332,31 @@ int HttpClient::put(const char* aURLPath, const char* aContentType, int aContent return startRequest(aURLPath, HTTP_METHOD_PUT, aContentType, aContentLength, aBody); } +int HttpClient::patch(const char* aURLPath) +{ + return startRequest(aURLPath, HTTP_METHOD_PATCH); +} + +int HttpClient::patch(const String& aURLPath) +{ + return patch(aURLPath.c_str()); +} + +int HttpClient::patch(const char* aURLPath, const char* aContentType, const char* aBody) +{ + return patch(aURLPath, aContentType, strlen(aBody), (const byte*)aBody); +} + +int HttpClient::patch(const String& aURLPath, const String& aContentType, const String& aBody) +{ + return patch(aURLPath.c_str(), aContentType.c_str(), aBody.length(), (const byte*)aBody.c_str()); +} + +int HttpClient::patch(const char* aURLPath, const char* aContentType, int aContentLength, const byte aBody[]) +{ + return startRequest(aURLPath, HTTP_METHOD_PATCH, aContentType, aContentLength, aBody); +} + int HttpClient::del(const char* aURLPath) { return startRequest(aURLPath, HTTP_METHOD_DELETE); diff --git a/src/HttpClient.h b/src/HttpClient.h index 141b2df..eaab360 100644 --- a/src/HttpClient.h +++ b/src/HttpClient.h @@ -29,6 +29,7 @@ static const int HTTP_ERROR_INVALID_RESPONSE =-4; #define HTTP_METHOD_GET "GET" #define HTTP_METHOD_POST "POST" #define HTTP_METHOD_PUT "PUT" +#define HTTP_METHOD_PATCH "PATCH" #define HTTP_METHOD_DELETE "DELETE" #define HTTP_HEADER_CONTENT_LENGTH "Content-Length" #define HTTP_HEADER_CONTENT_TYPE "Content-Type" @@ -104,6 +105,24 @@ public: int put(const String& aURLPath, const String& aContentType, const String& aBody); int put(const char* aURLPath, const char* aContentType, int aContentLength, const byte aBody[]); + /** Connect to the server and start to send a PATCH request. + @param aURLPath Url to request + @return 0 if successful, else error + */ + int patch(const char* aURLPath); + int patch(const String& aURLPath); + + /** Connect to the server and send a PATCH request + with body and content type + @param aURLPath Url to request + @param aContentType Content type of request body + @param aBody Body of the request + @return 0 if successful, else error + */ + int patch(const char* aURLPath, const char* aContentType, const char* aBody); + int patch(const String& aURLPath, const String& aContentType, const String& aBody); + int patch(const char* aURLPath, const char* aContentType, int aContentLength, const byte aBody[]); + /** Connect to the server and start to send a DELETE request. @param aURLPath Url to request @return 0 if successful, else error