Skip to content

Commit 9861072

Browse files
committed
AsyncWebSocket: Move strings to PROGMEM
1 parent 1f80d60 commit 9861072

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

src/AsyncWebSocket.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,14 +1223,14 @@ void AsyncWebSocket::binaryAll(const __FlashStringHelper *message, size_t len){
12231223
}
12241224
}
12251225

1226-
const char * WS_STR_CONNECTION = "Connection";
1227-
const char * WS_STR_UPGRADE = "Upgrade";
1228-
const char * WS_STR_ORIGIN = "Origin";
1229-
const char * WS_STR_VERSION = "Sec-WebSocket-Version";
1230-
const char * WS_STR_KEY = "Sec-WebSocket-Key";
1231-
const char * WS_STR_PROTOCOL = "Sec-WebSocket-Protocol";
1232-
const char * WS_STR_ACCEPT = "Sec-WebSocket-Accept";
1233-
const char * WS_STR_UUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
1226+
const char WS_STR_CONNECTION[] PROGMEM = "Connection";
1227+
const char WS_STR_UPGRADE[] PROGMEM = "Upgrade";
1228+
const char WS_STR_ORIGIN[] PROGMEM = "Origin";
1229+
const char WS_STR_VERSION[] PROGMEM = "Sec-WebSocket-Version";
1230+
const char WS_STR_KEY[] PROGMEM = "Sec-WebSocket-Key";
1231+
const char WS_STR_PROTOCOL[] PROGMEM = "Sec-WebSocket-Protocol";
1232+
const char WS_STR_ACCEPT[] PROGMEM = "Sec-WebSocket-Accept";
1233+
const char WS_STR_UUID[] PROGMEM = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
12341234

12351235
bool AsyncWebSocket::canHandle(AsyncWebServerRequest *request){
12361236
if(!_enabled)
@@ -1239,36 +1239,36 @@ bool AsyncWebSocket::canHandle(AsyncWebServerRequest *request){
12391239
if(request->method() != HTTP_GET || !request->url().equals(_url) || !request->isExpectedRequestedConnType(RCT_WS))
12401240
return false;
12411241

1242-
request->addInterestingHeader(WS_STR_CONNECTION);
1243-
request->addInterestingHeader(WS_STR_UPGRADE);
1244-
request->addInterestingHeader(WS_STR_ORIGIN);
1245-
request->addInterestingHeader(WS_STR_VERSION);
1246-
request->addInterestingHeader(WS_STR_KEY);
1247-
request->addInterestingHeader(WS_STR_PROTOCOL);
1242+
request->addInterestingHeader(FPSTR(WS_STR_CONNECTION));
1243+
request->addInterestingHeader(FPSTR(WS_STR_UPGRADE));
1244+
request->addInterestingHeader(FPSTR(WS_STR_ORIGIN));
1245+
request->addInterestingHeader(FPSTR(WS_STR_VERSION));
1246+
request->addInterestingHeader(FPSTR(WS_STR_KEY));
1247+
request->addInterestingHeader(FPSTR(WS_STR_PROTOCOL));
12481248
return true;
12491249
}
12501250

12511251
void AsyncWebSocket::handleRequest(AsyncWebServerRequest *request){
1252-
if(!request->hasHeader(WS_STR_VERSION) || !request->hasHeader(WS_STR_KEY)){
1252+
if(!request->hasHeader(FPSTR(WS_STR_VERSION)) || !request->hasHeader(FPSTR(WS_STR_KEY))){
12531253
request->send(400);
12541254
return;
12551255
}
12561256
if((_username != "" && _password != "") && !request->authenticate(_username.c_str(), _password.c_str())){
12571257
return request->requestAuthentication();
12581258
}
1259-
AsyncWebHeader* version = request->getHeader(WS_STR_VERSION);
1259+
AsyncWebHeader* version = request->getHeader(FPSTR(WS_STR_VERSION));
12601260
if(version->value().toInt() != 13){
12611261
AsyncWebServerResponse *response = request->beginResponse(400);
1262-
response->addHeader(WS_STR_VERSION,"13");
1262+
response->addHeader(FPSTR(WS_STR_VERSION),"13");
12631263
request->send(response);
12641264
return;
12651265
}
1266-
AsyncWebHeader* key = request->getHeader(WS_STR_KEY);
1266+
AsyncWebHeader* key = request->getHeader(FPSTR(WS_STR_KEY));
12671267
AsyncWebServerResponse *response = new AsyncWebSocketResponse(key->value(), this);
1268-
if(request->hasHeader(WS_STR_PROTOCOL)){
1269-
AsyncWebHeader* protocol = request->getHeader(WS_STR_PROTOCOL);
1268+
if(request->hasHeader(FPSTR(WS_STR_PROTOCOL))){
1269+
AsyncWebHeader* protocol = request->getHeader(FPSTR(WS_STR_PROTOCOL));
12701270
//ToDo: check protocol
1271-
response->addHeader(WS_STR_PROTOCOL, protocol->value());
1271+
response->addHeader(FPSTR(WS_STR_PROTOCOL), protocol->value());
12721272
}
12731273
request->send(response);
12741274
}
@@ -1324,9 +1324,9 @@ AsyncWebSocketResponse::AsyncWebSocketResponse(const String& key, AsyncWebSocket
13241324
char buffer[33];
13251325

13261326
#ifdef ESP8266
1327-
sha1(key + WS_STR_UUID, hash);
1327+
sha1(key + FPSTR(WS_STR_UUID), hash);
13281328
#else
1329-
(String&)key += WS_STR_UUID;
1329+
(String&)key += FPSTR(WS_STR_UUID);
13301330
mbedtls_sha1_context ctx;
13311331
mbedtls_sha1_init(&ctx);
13321332
mbedtls_sha1_starts_ret(&ctx);
@@ -1338,9 +1338,9 @@ AsyncWebSocketResponse::AsyncWebSocketResponse(const String& key, AsyncWebSocket
13381338
base64_init_encodestate(&_state);
13391339
int len = base64_encode_block((const char *) hash, 20, buffer, &_state);
13401340
len = base64_encode_blockend((buffer + len), &_state);
1341-
addHeader(WS_STR_CONNECTION, WS_STR_UPGRADE);
1342-
addHeader(WS_STR_UPGRADE, "websocket");
1343-
addHeader(WS_STR_ACCEPT,buffer);
1341+
addHeader(FPSTR(WS_STR_CONNECTION), FPSTR(WS_STR_UPGRADE));
1342+
addHeader(FPSTR(WS_STR_UPGRADE), F("websocket"));
1343+
addHeader(FPSTR(WS_STR_ACCEPT),buffer);
13441344
}
13451345

13461346
void AsyncWebSocketResponse::_respond(AsyncWebServerRequest *request){

0 commit comments

Comments
 (0)