From e4f81e16ea8664cf8ddea3e74026579b52de3b2e Mon Sep 17 00:00:00 2001 From: Alex Hultman Date: Wed, 3 Jun 2020 07:56:33 +0200 Subject: [PATCH] Don't set upgradedWebSocket outside the Http parser --- src/HttpContext.h | 11 ++++++++++- src/HttpContextData.h | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/HttpContext.h b/src/HttpContext.h index ced6f80..fed3ee7 100644 --- a/src/HttpContext.h +++ b/src/HttpContext.h @@ -120,6 +120,9 @@ private: /* Cork this socket */ ((AsyncSocket *) s)->cork(); + /* Mark that we are inside the parser now */ + httpContextData->isParsingHttp = true; + // clients need to know the cursor after http parse, not servers! // how far did we read then? we need to know to continue with websocket parsing data? or? @@ -220,6 +223,9 @@ private: return nullptr; }); + /* Mark that we are no longer parsing Http */ + httpContextData->isParsingHttp = false; + /* We need to uncork in all cases, except for nullptr (closed socket, or upgraded socket) */ if (returnedSocket != nullptr) { /* Timeout on uncork failure */ @@ -315,7 +321,10 @@ private: void upgradeToWebSocket(void *newSocket) { HttpContextData *httpContextData = getSocketContextData(); - httpContextData->upgradedWebSocket = newSocket; + /* We should only mark this if inside the parser; if upgrading "async" we cannot set this */ + if (httpContextData->isParsingHttp) { + httpContextData->upgradedWebSocket = newSocket; + } } public: diff --git a/src/HttpContextData.h b/src/HttpContextData.h index bfea9c8..5ba04bc 100644 --- a/src/HttpContextData.h +++ b/src/HttpContextData.h @@ -41,6 +41,7 @@ private: HttpRouter router; void *upgradedWebSocket = nullptr; + bool isParsingHttp = false; }; }