Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
30 changes: 21 additions & 9 deletions src/ESPAsyncWebServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -578,17 +575,32 @@ 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);
}
bool isSSE() const {
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:
Expand Down
19 changes: 6 additions & 13 deletions src/WebRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/literals.h
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Loading