feat: add ability to reject request

main
Sean McBride 4 years ago
parent 76ba308c16
commit e445e76870

@ -10,6 +10,7 @@
#include "http.h"
#define HTTP_RESPONSE_200_OK "HTTP/1.1 200 OK\r\n"
#define HTTP_RESPONSE_504_SERVICE_UNAVAILABLE "HTTP/1.1 504 Service Unavailable\r\n\r\n"
#define HTTP_RESPONSE_CONTENT_LENGTH "Content-Length: "
#define HTTP_RESPONSE_CONTENT_LENGTH_TERMINATOR "\r\n\r\n" /* content body follows this */
#define HTTP_RESPONSE_CONTENT_TYPE "Content-Type: "

@ -7,6 +7,7 @@
#include "global_request_scheduler_deque.h"
#include "global_request_scheduler_minheap.h"
#include "http_parser_settings.h"
#include "http_response.h"
#include "module.h"
#include "runtime.h"
#include "sandbox_request.h"
@ -115,10 +116,11 @@ listener_thread_main(void *dummy)
/*
* Reject Requests that exceed system capacity
* TODO: Enhance to gracefully return HTTP status code 503 Service Unavailable
*/
if (runtime_admitted + admissions_estimate >= runtime_worker_threads_count) {
debuglog("Would have rejected!");
send(socket_descriptor, HTTP_RESPONSE_504_SERVICE_UNAVAILABLE,
strlen(HTTP_RESPONSE_504_SERVICE_UNAVAILABLE), 0);
goto done;
}
/* Allocate a Sandbox Request */
@ -137,6 +139,7 @@ listener_thread_main(void *dummy)
}
}
done:
free(epoll_events);
return NULL;
}

Loading…
Cancel
Save