From 1c1a54318c109a110b299032d843ede5c3ed7f9b Mon Sep 17 00:00:00 2001 From: Mathieu Carbou Date: Fri, 31 Jul 2026 15:32:12 +0200 Subject: [PATCH] Removing dead code for RequestedConnectionType - RCT_NOT_USED unused only as a placeholder as a default param value - RCT_DEFAULT was partly mean RCT_HTTP but was never assigned, so hardly usable from user code. --- src/ESPAsyncWebServer.h | 30 +++++++++++++++++++++--------- src/WebRequest.cpp | 19 ++++++------------- src/literals.h | 2 -- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/ESPAsyncWebServer.h b/src/ESPAsyncWebServer.h index 2f872e0b..dbbd2313 100644 --- a/src/ESPAsyncWebServer.h +++ b/src/ESPAsyncWebServer.h @@ -395,12 +395,9 @@ class AsyncWebHeader { * */ typedef enum { - RCT_NOT_USED = -1, - RCT_DEFAULT = 0, - RCT_HTTP, - RCT_WS, - RCT_EVENT, - RCT_MAX + RCT_HTTP = 1, + RCT_WS = 2, + RCT_EVENT = 3 } RequestedConnectionType; // this enum is similar to Arduino WebServer's AsyncAuthType and PsychicHttp @@ -578,8 +575,22 @@ class AsyncWebServerRequest { RequestedConnectionType requestedConnType() const { return _reqconntype; } - bool isExpectedRequestedConnType(RequestedConnectionType erct1, RequestedConnectionType erct2 = RCT_NOT_USED, RequestedConnectionType erct3 = RCT_NOT_USED) - const; +#ifndef ESP8266 + [[deprecated("Use isExpectedRequestedConnType(RequestedConnectionType) instead")]] +#endif + bool isExpectedRequestedConnType(RequestedConnectionType erct1, RequestedConnectionType erct2, RequestedConnectionType erct3) const { + return isExpectedRequestedConnType(erct1) || isExpectedRequestedConnType(erct2) || isExpectedRequestedConnType(erct3); + } +#ifndef ESP8266 + [[deprecated("Use isExpectedRequestedConnType(RequestedConnectionType) instead")]] +#endif + bool isExpectedRequestedConnType(RequestedConnectionType erct1, RequestedConnectionType erct2) const { + return isExpectedRequestedConnType(erct1) || isExpectedRequestedConnType(erct2); + } + bool isExpectedRequestedConnType(RequestedConnectionType type) const { + return _reqconntype == type; + } + bool isWebSocketUpgrade() const { return _method == AsyncWebRequestMethod::HTTP_GET && isExpectedRequestedConnType(RCT_WS); } @@ -587,8 +598,9 @@ class AsyncWebServerRequest { return _method == AsyncWebRequestMethod::HTTP_GET && isExpectedRequestedConnType(RCT_EVENT); } bool isHTTP() const { - return isExpectedRequestedConnType(RCT_DEFAULT, RCT_HTTP); + return isExpectedRequestedConnType(RCT_HTTP); } + void onDisconnect(ArDisconnectHandler fn); // hash is the string representation of: diff --git a/src/WebRequest.cpp b/src/WebRequest.cpp index eb244c90..6822f875 100644 --- a/src/WebRequest.cpp +++ b/src/WebRequest.cpp @@ -663,7 +663,7 @@ bool AsyncWebServerRequest::_parseReqHeader() { // connection is still a plain HTTP connection so a previously detected // SSE request (or any other classified type) cannot be clobbered by // header ordering. - if (_method == AsyncWebRequestMethod::HTTP_GET && (_reqconntype == RCT_DEFAULT || _reqconntype == RCT_HTTP)) { + if (_method == AsyncWebRequestMethod::HTTP_GET && _reqconntype == RCT_HTTP) { _reqconntype = RCT_WS; } } else if (name.equalsIgnoreCase(T_ACCEPT)) { @@ -678,7 +678,7 @@ bool AsyncWebServerRequest::_parseReqHeader() { // Accept: text/event-stream. Only classify when the connection is still // a plain HTTP connection so a previously detected WebSocket upgrade // cannot be clobbered by header ordering. - if (substr != NULL && _method == AsyncWebRequestMethod::HTTP_GET && (_reqconntype == RCT_DEFAULT || _reqconntype == RCT_HTTP)) { + if (substr != NULL && _method == AsyncWebRequestMethod::HTTP_GET && _reqconntype == RCT_HTTP) { // WebEvent request can be uniquely identified by header: [Accept: text/event-stream] _reqconntype = RCT_EVENT; } @@ -1469,20 +1469,13 @@ String AsyncWebServerRequest::urlDecode(const String &text) const { const char *AsyncWebServerRequest::requestedConnTypeToString() const { switch (_reqconntype) { - case RCT_NOT_USED: return T_RCT_NOT_USED; - case RCT_DEFAULT: return T_RCT_DEFAULT; - case RCT_HTTP: return T_RCT_HTTP; - case RCT_WS: return T_RCT_WS; - case RCT_EVENT: return T_RCT_EVENT; - default: return T_ERROR; + case RCT_HTTP: return T_RCT_HTTP; + case RCT_WS: return T_RCT_WS; + case RCT_EVENT: return T_RCT_EVENT; + default: return T_ERROR; } } -bool AsyncWebServerRequest::isExpectedRequestedConnType(RequestedConnectionType erct1, RequestedConnectionType erct2, RequestedConnectionType erct3) const { - return ((erct1 != RCT_NOT_USED) && (erct1 == _reqconntype)) || ((erct2 != RCT_NOT_USED) && (erct2 == _reqconntype)) - || ((erct3 != RCT_NOT_USED) && (erct3 == _reqconntype)); -} - AsyncClient *AsyncWebServerRequest::clientRelease() { AsyncClient *c = _client; _client = nullptr; diff --git a/src/literals.h b/src/literals.h index 4f16b33b..5d12fcf2 100644 --- a/src/literals.h +++ b/src/literals.h @@ -139,8 +139,6 @@ static constexpr const char T_LINK[] = "LINK"; static constexpr const char T_UNLINK[] = "UNLINK"; // Req content types -static constexpr const char T_RCT_NOT_USED[] = "RCT_NOT_USED"; -static constexpr const char T_RCT_DEFAULT[] = "RCT_DEFAULT"; static constexpr const char T_RCT_HTTP[] = "RCT_HTTP"; static constexpr const char T_RCT_WS[] = "RCT_WS"; static constexpr const char T_RCT_EVENT[] = "RCT_EVENT";