From 4a66056e5ff8115ee99e21133442efae21e85a82 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sat, 1 May 2021 17:12:00 +0200 Subject: [PATCH 1/2] Support additional headers in WebSocketClient --- src/WebSocketClient.cpp | 31 ++++++++++++++++++++----------- src/WebSocketClient.h | 7 +++++++ 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/WebSocketClient.cpp b/src/WebSocketClient.cpp index ab41b0a..a892dff 100644 --- a/src/WebSocketClient.cpp +++ b/src/WebSocketClient.cpp @@ -12,7 +12,7 @@ WebSocketClient::WebSocketClient(Client& aClient, const char* aServerName, uint1 { } -WebSocketClient::WebSocketClient(Client& aClient, const String& aServerName, uint16_t aServerPort) +WebSocketClient::WebSocketClient(Client& aClient, const String& aServerName, uint16_t aServerPort) : HttpClient(aClient, aServerName, aServerPort), iTxStarted(false), iRxSize(0) @@ -26,7 +26,7 @@ WebSocketClient::WebSocketClient(Client& aClient, const IPAddress& aServerAddres { } -int WebSocketClient::begin(const char* aPath) +int WebSocketClient::begin(const char* aPath, char* (*additionalHeaders)[2], size_t headerRows) { // start the GET request beginRequest(); @@ -51,6 +51,10 @@ int WebSocketClient::begin(const char* aPath) sendHeader("Connection", "Upgrade"); sendHeader("Sec-WebSocket-Key", base64RandomKey); sendHeader("Sec-WebSocket-Version", "13"); + for (size_t i = 0; i < headerRows; ++i) + { + sendHeader(additionalHeaders[i][0], additionalHeaders[i][1]); + } endRequest(); status = responseStatusCode(); @@ -67,9 +71,14 @@ int WebSocketClient::begin(const char* aPath) return (status == 101) ? 0 : status; } +int WebSocketClient::begin(const char* aPath) +{ + return begin(aPath, NULL, 0); +} + int WebSocketClient::begin(const String& aPath) { - return begin(aPath.c_str()); + return begin(aPath.c_str(), NULL, 0); } int WebSocketClient::beginMessage(int aType) @@ -174,7 +183,7 @@ size_t WebSocketClient::write(const uint8_t *aBuffer, size_t aSize) memcpy(iTxBuffer + iTxSize, aBuffer, aSize); iTxSize += aSize; - + return aSize; } @@ -217,14 +226,14 @@ int WebSocketClient::parseMessage() } else { - iRxSize = ((uint64_t)HttpClient::read() << 56) | - ((uint64_t)HttpClient::read() << 48) | - ((uint64_t)HttpClient::read() << 40) | - ((uint64_t)HttpClient::read() << 32) | - ((uint64_t)HttpClient::read() << 24) | - ((uint64_t)HttpClient::read() << 16) | + iRxSize = ((uint64_t)HttpClient::read() << 56) | + ((uint64_t)HttpClient::read() << 48) | + ((uint64_t)HttpClient::read() << 40) | + ((uint64_t)HttpClient::read() << 32) | + ((uint64_t)HttpClient::read() << 24) | + ((uint64_t)HttpClient::read() << 16) | ((uint64_t)HttpClient::read() << 8) | - (uint64_t)HttpClient::read(); + (uint64_t)HttpClient::read(); } // read in the mask, if present diff --git a/src/WebSocketClient.h b/src/WebSocketClient.h index 4b009e6..b661146 100644 --- a/src/WebSocketClient.h +++ b/src/WebSocketClient.h @@ -22,6 +22,13 @@ class WebSocketClient : public HttpClient WebSocketClient(Client& aClient, const String& aServerName, uint16_t aServerPort = HttpClient::kHttpPort); WebSocketClient(Client& aClient, const IPAddress& aServerAddress, uint16_t aServerPort = HttpClient::kHttpPort); + /** Start the Web Socket connection to the specified path with headers + @param aPath Path to use in request + @param additionalHeaders 2D array with headers + @param headerRows amound of rows in additionalHeaders array + @return 0 if successful, else error + */ + int begin(const char* aPath, char* (*additionalHeaders)[2], size_t headerRows); /** Start the Web Socket connection to the specified path @param aURLPath Path to use in request (optional, "/" is used by default) @return 0 if successful, else error From a142ab269963134377a638e669ee54bd649b856f Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Mon, 10 May 2021 09:32:55 +0200 Subject: [PATCH 2/2] Fix typo in param comment --- src/WebSocketClient.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WebSocketClient.h b/src/WebSocketClient.h index b661146..d87a28e 100644 --- a/src/WebSocketClient.h +++ b/src/WebSocketClient.h @@ -25,7 +25,7 @@ class WebSocketClient : public HttpClient /** Start the Web Socket connection to the specified path with headers @param aPath Path to use in request @param additionalHeaders 2D array with headers - @param headerRows amound of rows in additionalHeaders array + @param headerRows amount of rows in additionalHeaders array @return 0 if successful, else error */ int begin(const char* aPath, char* (*additionalHeaders)[2], size_t headerRows); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy