Guarantee to end http parsing after websocket upgrade

This commit is contained in:
Alex Hultman
2019-04-04 00:21:27 +02:00
parent 41ed5e3990
commit b36607dac6
+19 -4
View File
@@ -120,6 +120,8 @@ private:
// clients need to know the cursor after http parse, not servers! // 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? // how far did we read then? we need to know to continue with websocket parsing data? or?
/* The return value is entirely up to us to interpret. The HttpParser only care for whether the returned value is DIFFERENT or not from passed user */
void *returnedSocket = httpResponseData->consumePostPadded(data, length, s, [httpContextData](void *s, uWS::HttpRequest *httpRequest) -> void * { void *returnedSocket = httpResponseData->consumePostPadded(data, length, s, [httpContextData](void *s, uWS::HttpRequest *httpRequest) -> void * {
/* For every request we reset the timeout and hang until user makes action */ /* For every request we reset the timeout and hang until user makes action */
/* Warning: if we are in shutdown state, resetting the timer is a security issue! */ /* Warning: if we are in shutdown state, resetting the timer is a security issue! */
@@ -151,10 +153,8 @@ private:
/* First of all we need to check if this socket was deleted due to upgrade */ /* First of all we need to check if this socket was deleted due to upgrade */
if (httpContextData->upgradedWebSocket) { if (httpContextData->upgradedWebSocket) {
/* Reset upgradedWebSocket before we return */ /* We differ between closed and upgraded below */
void *tmp = httpContextData->upgradedWebSocket; return nullptr;
httpContextData->upgradedWebSocket = nullptr;
return tmp;
} }
/* Was the socket closed? */ /* Was the socket closed? */
@@ -222,6 +222,21 @@ private:
return (us_new_socket_t *) returnedSocket; return (us_new_socket_t *) returnedSocket;
} }
/* If we upgraded, check here (differ between nullptr close and nullptr upgrade) */
if (httpContextData->upgradedWebSocket) {
/* This path is only for upgraded websockets */
AsyncSocket<SSL> *asyncSocket = (AsyncSocket<SSL> *) httpContextData->upgradedWebSocket;
/* Uncork here as well (note: what if we failed to uncork and we then pub/sub before we even upgraded?) */
auto [written, failed] = asyncSocket->uncork();
/* Reset upgradedWebSocket before we return */
httpContextData->upgradedWebSocket = nullptr;
/* Return the new upgraded websocket */
return (us_new_socket_t *) asyncSocket;
}
/* We cannot return nullptr to the underlying stack in any case */ /* We cannot return nullptr to the underlying stack in any case */
return s; return s;
}); });