update readme and actually add responses to non-GET requests

This commit is contained in:
Nayan
2025-05-08 20:07:08 -04:00
parent 8d60863be3
commit 6a17569284
7 changed files with 163 additions and 3 deletions

View File

@@ -29,6 +29,27 @@ void response_handle_get(http_request* req, http_response* res) {
}
}
void response_handle_post(http_request* req, http_response* res) {
// TODO
printf("POST request\n");
printf("%s\n", req->url);
serve_501(res);
}
void response_handle_delete(http_request* req, http_response* res) {
// TODO
printf("DELETE request\n");
printf("%s\n", req->url);
serve_501(res);
}
void response_handle_put(http_request* req, http_response* res) {
// TODO
printf("PUT request\n");
printf("%s\n", req->url);
serve_501(res);
}
void response_build_static_file(char* file_path, content_type content_type,
status_code status_code, http_response* res) {
// Open the file and verify that the file exists
@@ -85,6 +106,10 @@ void response_build_static_file(char* file_path, content_type content_type,
strcat(status_line, "500 Internal Server Error");
break;
case FORBIDDEN:
strcat(status_line, "403 Forbidden");
break;
default:
strcat(status_line, "501 Not Implemented");
break;
@@ -147,4 +172,19 @@ void serve_404(http_response* res) {
void serve_500(http_response* res) {
char* file_path = "./public/500.html";
response_build_static_file(file_path, HTML, INTERNAL_SERVER_ERROR, res);
}
void serve_403(http_response* res) {
char* file_path = "./public/403.html";
response_build_static_file(file_path, HTML, FORBIDDEN, res);
}
void serve_501(http_response* res) {
char* file_path = "./public/501.html";
response_build_static_file(file_path, HTML, NOT_IMPLEMENTED, res);
}
void serve_400(http_response* res) {
char* file_path = "./public/400.html";
response_build_static_file(file_path, HTML, BAD_REQUEST, res);
}