8000 mandatoryHttpHeaderCount fix · robokoding/arduinoWebSockets@7e5c64a · GitHub
[go: up one dir, main page]

Skip to content

Commit 7e5c64a

Browse files
committed
mandatoryHttpHeaderCount fix
1 parent 97443ae commit 7e5c64a

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

examples/WebSocketServer/WebSocketServerHttpHeaderValidation.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ void setup() {
7575

7676
//connecting clients must supply a valid session cookie at websocket upgrade handshake negotiation time
7777
const char * headerkeys[] = { "Cookie" };
78-
webSocket.onValidateHttpHeader(validateHttpHeader, headerkeys);
78+
size_t headerKeyCount = sizeof(headerkeys) / sizeof(char*);
79+
webSocket.onValidateHttpHeader(validateHttpHeader, headerkeys, headerKeyCount);
7980
webSocket.begin();
8081
}
8182

src/WebSocketsServer.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,18 +129,20 @@ void WebSocketsServer::onEvent(WebSocketServerEvent cbEvent) {
129129
/*
130130
* Sets the custom http header validator function
131131
* @param httpHeaderValidationFunc WebSocketServerHttpHeaderValFunc ///< pointer to the custom http header validation function
132-
* @param mandatoryHttpHeaders const char* ///< the array of named http headers considered to be mandatory / must be present in order for websocket upgrade to succeed
132+
* @param mandatoryHttpHeaders[] const char* ///< the array of named http headers considered to be mandatory / must be present in order for websocket upgrade to succeed
133+
* @param mandatoryHttpHeaderCount size_t ///< the number of items in the mandatoryHttpHeaders array
133134
*/
134135
void WebSocketsServer::onValidateHttpHeader(
135136
WebSocketServerHttpHeaderValFunc validationFunc,
136-
const char* mandatoryHttpHeaders[])
137+
const char* mandatoryHttpHeaders[],
138+
size_t mandatoryHttpHeaderCount)
137139
{
138140
_httpHeaderValidationFunc = validationFunc;
139141

140142
if (_mandatoryHttpHeaders)
141143
delete[] _mandatoryHttpHeaders;
142144

143-
_mandatoryHttpHeaderCount = (sizeof(mandatoryHttpHeaders) / sizeof(char*));
145+
_mandatoryHttpHeaderCount = mandatoryHttpHeaderCount;
144146
_mandatoryHttpHeaders = new String[_mandatoryHttpHeaderCount];
145147

146148
for (size_t i = 0; i < _mandatoryHttpHeaderCount; i++) {

src/WebSocketsServer.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ class WebSocketsServer: private WebSockets {
5757
#endif
5858

5959
void onEvent(WebSocketServerEvent cbEvent);
60-
void onValidateHttpHeader(WebSocketServerHttpHeaderValFunc validationFunc, const char* mandatoryHttpHeaders[]);
60+
void onValidateHttpHeader(
61+
WebSocketServerHttpHeaderValFunc validationFunc,
62+
const char* mandatoryHttpHeaders[],
63+
size_t mandatoryHttpHeaderCount);
6164

6265

6366
bool sendTXT(uint8_t num, uint8_t * payload, size_t length = 0, bool headerToPayload = false);

0 commit comments

Comments
 (0)
0