From 497a05f1833403d26a8c2bc53f0a0d3a8410a8b9 Mon Sep 17 00:00:00 2001 From: Alec Murphy Date: Sun, 30 Mar 2025 19:07:31 -0400 Subject: [PATCH] Slon/Http/Server: Set SLON_HTTP_REQUEST_TIMEOUT at 3000 ms --- Slon/Http/Server.HC | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/Slon/Http/Server.HC b/Slon/Http/Server.HC index 7802e25..f248724 100644 --- a/Slon/Http/Server.HC +++ b/Slon/Http/Server.HC @@ -1,4 +1,5 @@ #define SLON_DEBUG_PRINT_REQUEST_JSON IntNop; +#define SLON_HTTP_REQUEST_TIMEOUT 3000 SlonHttpBuffer* @slon_http_init_buffer(SlonHttpSession* session) { @@ -809,12 +810,15 @@ U0 @slon_http_handle_request(SlonHttpSession* session) U0 @slon_http_task(TcpSocket* s) { // Bail if we can't acquire socket for some reason - if (!@tcp_socket_accept(s)) - return; + if (!@tcp_socket_accept(s)) { + Kill(Fs); + } // Init session SlonHttpSession* session = @slon_http_init_session(s); + I64 start_jiffies = cnts.jiffies; + // Parse headers if they are available while (!@slon_http_request_headers_have_been_parsed(session)) { @slon_http_receive(session); @@ -826,6 +830,11 @@ U0 @slon_http_task(TcpSocket* s) } @slon_http_try_parse_request_headers(session); + + if (cnts.jiffies > start_jiffies + SLON_HTTP_REQUEST_TIMEOUT) { + s->close(); + Kill(Fs); + } } //@slon_http_debug_print_request(session, FALSE); @@ -833,8 +842,14 @@ U0 @slon_http_task(TcpSocket* s) // If we have a content-length header, consume until we receive all the data, then set request->data pointer and size if (StrLen(session->header("content-length"))) { I64 content_length = Str2I64(session->header("content-length")); - while (session->request->buffer->data + session->request->buffer->size - session->request->data < content_length) + start_jiffies = cnts.jiffies; + while (session->request->buffer->data + session->request->buffer->size - session->request->data < content_length) { @slon_http_receive(session); + if (cnts.jiffies > start_jiffies + SLON_HTTP_REQUEST_TIMEOUT) { + s->close(); + Kill(Fs); + } + } } @slon_http_handle_request(session);