diff options
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) { |
