Slon/Http/Server: Set SLON_HTTP_REQUEST_TIMEOUT at 3000 ms

This commit is contained in:
Alec Murphy 2025-03-30 19:07:31 -04:00
parent 2dc8eac296
commit 497a05f183

View file

@ -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);