From b6951c18912c82e7863ebd6c6c77b891ad9aea0c Mon Sep 17 00:00:00 2001 From: frosty Date: Sat, 8 Aug 2026 00:37:44 -0400 Subject: fix: centralise empty HTTP status responses --- src/http.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/http.c') diff --git a/src/http.c b/src/http.c index 891fca3..778bf51 100644 --- a/src/http.c +++ b/src/http.c @@ -48,6 +48,26 @@ static void build_cookie_headers(char *cookie_headers_buffer, } } +void send_status(const char *status_line) { + if (current_client_socket == -1) { + fprintf(stderr, "[ERROR] send_status: No client socket set. Cannot send response.\n"); + return; + } + + char http_response[BUFFER_SIZE]; + snprintf(http_response, sizeof(http_response), + "HTTP/1.1 %s\r\n" + "Content-Length: 0\r\n" + "Connection: close\r\n" + "\r\n", + status_line); + + if (send(current_client_socket, http_response, strlen(http_response), 0) < 0) { + perror("Error sending HTTP status"); + fprintf(stderr, "[ERROR] send_status: Failed to send HTTP status.\n"); + } +} + void send_response(const char *html) { if (current_client_socket == -1) { -- cgit v1.3