// HTTP Web Server // Jack Sangdahl // 09 October 2024 #include #include #include #include #include #include #include #include #include #include #define DATA_SIZE 8192 #define CONTENT_TYPE_SIZE 32 #define KEEP_ALIVE_TIMEOUT 10 #define RESP_400 \ "HTTP/1.1 400 Bad Request\r\n" \ "Content-Type: text/html\r\n" \ "Content-Length: 159\r\n\r\n" \ "

400 Bad Request

The request could not be " \ "parsed or is malformed

" #define RESP_403 \ "HTTP/1.1 403 Forbidden\r\n" \ "Content-Type: text/html\r\n" \ "Content-Length: 207\r\n\r\n" \ "

403 Forbidden

The requested file can not " \ "be accessed due to afile permission issue

" #define RESP_404 \ "HTTP/1.1 404 Not Found\r\n" \ "Content-Type: text/html\r\n" \ "Content-Length: 195\r\n\r\n" \ "

404 Not Found

The requested file can not " \ "be found in the document tree

" #define RESP_405 \ "HTTP/1.1 405 Method Not Allowed\r\n" \ "Content-Type: text/html\r\n" \ "Content-Length: 194\r\n\r\n" \ "

405 Method Not Allowed

A method other " \ "than GET was requested

" #define RESP_505 \ "HTTP/1.1 505 HTTP Version Not Supported\r\n" \ "Content-Type: text/html\r\n" \ "Content-Length: 224\r\n\r\n" \ "

505 HTTP Version Not Supported

An HTTP " \ "version other than 1.0 or 1.1 was requested

" struct file_ext_map { char *ext; char *type; }; void *handle_connection(void *a); int handle_request(int connection, char *filename, char *version, bool keep_alive); int handle_error(int connection, int error_code); void handle_sigint(int sig);