Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Support additional headers in WebSocketClient#104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
MSchmidt wants to merge3 commits intoarduino-libraries:master
base:master
Choose a base branch
Loading
fromMSchmidt:master
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletionssrc/WebSocketClient.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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)
Expand All@@ -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();
Expand All@@ -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();
Expand All@@ -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)
Expand DownExpand Up@@ -174,7 +183,7 @@ size_t WebSocketClient::write(const uint8_t *aBuffer, size_t aSize)
memcpy(iTxBuffer + iTxSize, aBuffer, aSize);

iTxSize += aSize;

return aSize;
}

Expand DownExpand Up@@ -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
Expand Down
7 changes: 7 additions & 0 deletionssrc/WebSocketClient.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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 amount 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
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp