From 87aea5a28cb98f920ffb8a2cc267de229ca6c1e4 Mon Sep 17 00:00:00 2001 From: Alex Hultman Date: Tue, 22 Jan 2019 09:28:03 +0100 Subject: [PATCH] Don't emit multiple parallel requests --- src/HttpContext.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/HttpContext.h b/src/HttpContext.h index af093d5..bc09141 100644 --- a/src/HttpContext.h +++ b/src/HttpContext.h @@ -76,8 +76,6 @@ private: f((HttpResponse *) s, 1); } - // todo: handle filter closing the socket? - return s; }); @@ -135,6 +133,14 @@ private: HttpResponseData *httpResponseData = (HttpResponseData *) static_dispatch(us_ssl_socket_ext, us_socket_ext)((SOCKET_TYPE *) s); httpResponseData->offset = 0; httpResponseData->state = 0; + + /* Are we not ready for another request yet? Terminate the connection. */ + if (httpResponseData->state & HttpResponseData::HTTP_RESPONSE_PENDING) { + static_dispatch(us_ssl_socket_close, us_socket_close)((SOCKET_TYPE *) s); + return nullptr; + } + + /* Mark pending request and emit it */ httpResponseData->state |= HttpResponseData::HTTP_RESPONSE_PENDING; /* Route the method and URL (unhandled should close or end it by default) */ @@ -163,7 +169,7 @@ private: /* Returning from a request handler without responding or attaching an onAborted handler is ill-use */ if (!((HttpResponse *) s)->hasResponded() && !httpResponseData->onAborted) { /* Throw exception here? */ - std::cerr << "µWebSockets ill-use: Returning from a request handler without responding or attaching an abort handler is forbidden." << std::endl; + std::cerr << "Error: Returning from a request handler without responding or attaching an abort handler is forbidden!" << std::endl; std::terminate(); } @@ -203,15 +209,13 @@ private: return (SOCKET_TYPE *) returnedSocket; } - // we cannot return nullptr to the underlying stack in any case + /* We cannot return nullptr to the underlying stack in any case */ return s; }); /* Handle HTTP write out (note: SSL_read may trigger this spuriously, the app need to handle spurious calls) */ static_dispatch(us_ssl_socket_context_on_writable, us_socket_context_on_writable)(getSocketContext(), [](auto *s) { - //std::cout << "HttpContext::onWritable event fired!" << std::endl; - /* We are now writable, so hang timeout again */ static_dispatch(us_ssl_socket_timeout, us_socket_timeout)(s, 0);