Skip to content

Commit 097bfaf

Browse files
committed
Removing dead code for RequestedConnectionType
- RCT_NOT_USED unused only as a placeholder as a default param valuye ( - RCT_DEFAULT was partly mean RCT_HTTP but was never assigned, so hardly usable from user code.
1 parent f443b9a commit 097bfaf

3 files changed

Lines changed: 23 additions & 20 deletions

File tree

src/ESPAsyncWebServer.h

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -395,12 +395,9 @@ class AsyncWebHeader {
395395
* */
396396

397397
typedef enum {
398-
RCT_NOT_USED = -1,
399-
RCT_DEFAULT = 0,
400-
RCT_HTTP,
401-
RCT_WS,
402-
RCT_EVENT,
403-
RCT_MAX
398+
RCT_HTTP = 1,
399+
RCT_WS = 2,
400+
RCT_EVENT = 3
404401
} RequestedConnectionType;
405402

406403
// this enum is similar to Arduino WebServer's AsyncAuthType and PsychicHttp
@@ -578,17 +575,32 @@ class AsyncWebServerRequest {
578575
RequestedConnectionType requestedConnType() const {
579576
return _reqconntype;
580577
}
581-
bool isExpectedRequestedConnType(RequestedConnectionType erct1, RequestedConnectionType erct2 = RCT_NOT_USED, RequestedConnectionType erct3 = RCT_NOT_USED)
582-
const;
578+
#ifndef ESP8266
579+
[[deprecated("Use isExpectedRequestedConnType(RequestedConnectionType) instead")]]
580+
#endif
581+
bool isExpectedRequestedConnType(RequestedConnectionType erct1, RequestedConnectionType erct2, RequestedConnectionType erct3) const {
582+
return isExpectedRequestedConnType(erct1) || isExpectedRequestedConnType(erct2) || isExpectedRequestedConnType(erct3);
583+
}
584+
#ifndef ESP8266
585+
[[deprecated("Use isExpectedRequestedConnType(RequestedConnectionType) instead")]]
586+
#endif
587+
bool isExpectedRequestedConnType(RequestedConnectionType erct1, RequestedConnectionType erct2) const {
588+
return isExpectedRequestedConnType(erct1) || isExpectedRequestedConnType(erct2);
589+
}
590+
bool isExpectedRequestedConnType(RequestedConnectionType type) const {
591+
return _reqconntype == type;
592+
}
593+
583594
bool isWebSocketUpgrade() const {
584595
return _method == AsyncWebRequestMethod::HTTP_GET && isExpectedRequestedConnType(RCT_WS);
585596
}
586597
bool isSSE() const {
587598
return _method == AsyncWebRequestMethod::HTTP_GET && isExpectedRequestedConnType(RCT_EVENT);
588599
}
589600
bool isHTTP() const {
590-
return isExpectedRequestedConnType(RCT_DEFAULT, RCT_HTTP);
601+
return isExpectedRequestedConnType(RCT_HTTP);
591602
}
603+
592604
void onDisconnect(ArDisconnectHandler fn);
593605

594606
// hash is the string representation of:

src/WebRequest.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ bool AsyncWebServerRequest::_parseReqHeader() {
663663
// connection is still a plain HTTP connection so a previously detected
664664
// SSE request (or any other classified type) cannot be clobbered by
665665
// header ordering.
666-
if (_method == AsyncWebRequestMethod::HTTP_GET && (_reqconntype == RCT_DEFAULT || _reqconntype == RCT_HTTP)) {
666+
if (_method == AsyncWebRequestMethod::HTTP_GET && _reqconntype == RCT_HTTP) {
667667
_reqconntype = RCT_WS;
668668
}
669669
} else if (name.equalsIgnoreCase(T_ACCEPT)) {
@@ -678,7 +678,7 @@ bool AsyncWebServerRequest::_parseReqHeader() {
678678
// Accept: text/event-stream. Only classify when the connection is still
679679
// a plain HTTP connection so a previously detected WebSocket upgrade
680680
// cannot be clobbered by header ordering.
681-
if (substr != NULL && _method == AsyncWebRequestMethod::HTTP_GET && (_reqconntype == RCT_DEFAULT || _reqconntype == RCT_HTTP)) {
681+
if (substr != NULL && _method == AsyncWebRequestMethod::HTTP_GET && _reqconntype == RCT_HTTP) {
682682
// WebEvent request can be uniquely identified by header: [Accept: text/event-stream]
683683
_reqconntype = RCT_EVENT;
684684
}
@@ -1469,20 +1469,13 @@ String AsyncWebServerRequest::urlDecode(const String &text) const {
14691469

14701470
const char *AsyncWebServerRequest::requestedConnTypeToString() const {
14711471
switch (_reqconntype) {
1472-
case RCT_NOT_USED: return T_RCT_NOT_USED;
1473-
case RCT_DEFAULT: return T_RCT_DEFAULT;
14741472
case RCT_HTTP: return T_RCT_HTTP;
14751473
case RCT_WS: return T_RCT_WS;
14761474
case RCT_EVENT: return T_RCT_EVENT;
14771475
default: return T_ERROR;
14781476
}
14791477
}
14801478

1481-
bool AsyncWebServerRequest::isExpectedRequestedConnType(RequestedConnectionType erct1, RequestedConnectionType erct2, RequestedConnectionType erct3) const {
1482-
return ((erct1 != RCT_NOT_USED) && (erct1 == _reqconntype)) || ((erct2 != RCT_NOT_USED) && (erct2 == _reqconntype))
1483-
|| ((erct3 != RCT_NOT_USED) && (erct3 == _reqconntype));
1484-
}
1485-
14861479
AsyncClient *AsyncWebServerRequest::clientRelease() {
14871480
AsyncClient *c = _client;
14881481
_client = nullptr;

src/literals.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,6 @@ static constexpr const char T_LINK[] = "LINK";
139139
static constexpr const char T_UNLINK[] = "UNLINK";
140140

141141
// Req content types
142-
static constexpr const char T_RCT_NOT_USED[] = "RCT_NOT_USED";
143-
static constexpr const char T_RCT_DEFAULT[] = "RCT_DEFAULT";
144142
static constexpr const char T_RCT_HTTP[] = "RCT_HTTP";
145143
static constexpr const char T_RCT_WS[] = "RCT_WS";
146144
static constexpr const char T_RCT_EVENT[] = "RCT_EVENT";

0 commit comments

Comments
 (0)