diff options
| author | frosty <gabriel@bwaaa.monster> | 2026-08-08 00:37:44 -0400 |
|---|---|---|
| committer | frosty <gabriel@bwaaa.monster> | 2026-08-08 00:37:44 -0400 |
| commit | b6951c18912c82e7863ebd6c6c77b891ad9aea0c (patch) | |
| tree | 7e7e067b93b4df878f000ec4a272334a81aba85f /src/http.c | |
| parent | 42fe6caf63acdd25e5674d91c13a9ab15f948b7f (diff) | |
| download | beaker-b6951c18912c82e7863ebd6c6c77b891ad9aea0c.tar.gz | |
fix: centralise empty HTTP status responses
Diffstat (limited to 'src/http.c')
| -rw-r--r-- | src/http.c | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -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) { |
