diff --git a/public/400.html b/public/400.html
new file mode 100644
index 0000000..8e3ea50
--- /dev/null
+++ b/public/400.html
@@ -0,0 +1,34 @@
+
+
+
+ Document
+
+
+
+
+
Error 400: Bad Request
+
+
\ No newline at end of file
diff --git a/public/403.html b/public/403.html
new file mode 100644
index 0000000..63a3086
--- /dev/null
+++ b/public/403.html
@@ -0,0 +1,34 @@
+
+
+
+ Document
+
+
+
+
+
Error 403: Forbidden
+
+
\ No newline at end of file
diff --git a/public/501.html b/public/501.html
new file mode 100644
index 0000000..3363799
--- /dev/null
+++ b/public/501.html
@@ -0,0 +1,34 @@
+
+
+
+ Document
+
+
+
+
+
Error 501: Not Implemented
+
+
\ No newline at end of file
diff --git a/readme.md b/readme.md
index 0fcf498..1dd5c14 100644
--- a/readme.md
+++ b/readme.md
@@ -3,6 +3,10 @@ The HTTP server has gotten much larger and more complex than I originally antici
This evening I finally worked through the bugs on handling file serving, and have been able to get it working with arbitrary file types. They are still restricted "for security reasons," but it can theoretically be expanded to any file type.
+The server does not handle routes, only raw file paths, and also does not include the templating engine that I was planning to include, but I simply ran out of time. After doing a little research I have also decided to scrap the idea of implementing file uploading, since parsing streamed files is a lot more complex than I can tackle in the time I have left.
+
+I will implement logging to a log file to satisfy the file writing requirement.
+
## Final Project Plan Update
Even though I haven't had time to work on it, I have been turning this project over in my mind for the past two weeks. I have wanted to build my own basic HTTP server for a while, and this is the only piece of homework due this week, so I have decided to make my final project a basic HTTP server.
diff --git a/request_handler.c b/request_handler.c
index 8e4c313..0f84171 100644
--- a/request_handler.c
+++ b/request_handler.c
@@ -19,15 +19,15 @@ void handle_request(char* request, int length, http_response* response) {
break;
case POST:
- /* code */
+ response_handle_post(req, response);
break;
case PUT:
- /* code */
+ response_handle_put(req, response);
break;
case DELETE:
- /* code */
+ response_handle_delete(req, response);
break;
}
diff --git a/response_builder.c b/response_builder.c
index c20dee4..fa7c9cd 100644
--- a/response_builder.c
+++ b/response_builder.c
@@ -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);
}
\ No newline at end of file
diff --git a/response_builder.h b/response_builder.h
index 11d7391..c4c33a3 100644
--- a/response_builder.h
+++ b/response_builder.h
@@ -20,10 +20,18 @@ typedef enum {
NOT_FOUND,
BAD_REQUEST,
INTERNAL_SERVER_ERROR,
+ FORBIDDEN,
+ NOT_IMPLEMENTED,
} status_code;
void response_handle_get(http_request* req, http_response* res);
+void response_handle_post(http_request* req, http_response* res);
+
+void response_handle_delete(http_request* req, http_response* res);
+
+void response_handle_put(http_request* req, http_response* res);
+
void response_build_static_file(char* file_path, content_type content_type,
status_code status_code, http_response* res);
@@ -31,4 +39,10 @@ void serve_404(http_response* res);
void serve_500(http_response* res);
+void serve_403(http_response* res);
+
+void serve_501(http_response* res);
+
+void serve_400(http_response* res);
+
#endif
\ No newline at end of file