diff --git a/srcs/utils.hpp b/srcs/utils.hpp index 7933552..b59df2f 100644 --- a/srcs/utils.hpp +++ b/srcs/utils.hpp @@ -17,7 +17,7 @@ // GET = 0b00000001, // POST = 0b00000010, // DELETE = 0b00000100, -// ALL_METHODS = 0b11111111, +// ANY_METHODS = 0b11111111, // }; enum http_method @@ -26,7 +26,7 @@ enum http_method GET = 1 << 0, POST = 1 << 1, DELETE = 1 << 2, - ALL_METHODS = 0b11111111, + ANY_METHODS = 0b11111111, }; std::vector split(std::string input, char delimiter); diff --git a/srcs/webserv/http_status.hpp b/srcs/webserv/http_status.hpp index 8aa513a..d6017f0 100644 --- a/srcs/webserv/http_status.hpp +++ b/srcs/webserv/http_status.hpp @@ -37,5 +37,6 @@ # define S413 "413 Content Too Large" # define S500 "500 Internal Server Error" +# define S501 "501 Not Implemented" #endif diff --git a/srcs/webserv/init.cpp b/srcs/webserv/init.cpp index ddd0edc..361eaa2 100644 --- a/srcs/webserv/init.cpp +++ b/srcs/webserv/init.cpp @@ -90,6 +90,7 @@ void Webserv::_init_http_status_map() _http_status[413] = S413; _http_status[500] = S500; + _http_status[501] = S501; } void Webserv::_init_mime_types_map() diff --git a/srcs/webserv/response.cpp b/srcs/webserv/response.cpp index 0b6f3fa..405d0a7 100644 --- a/srcs/webserv/response.cpp +++ b/srcs/webserv/response.cpp @@ -66,6 +66,7 @@ void Webserv::_append_base_headers(Client *client) void Webserv::_construct_response(Client *client, ServerConfig &server) { + // TODO : Move this in read(), stop read if content too large if (client->get_body().size() > server.client_body_limit) { client->status = 413; @@ -77,27 +78,24 @@ void Webserv::_construct_response(Client *client, ServerConfig &server) void Webserv::_process_method(Client *client, ServerConfig &server, LocationConfig &location) { - unsigned int allow_methods = ALL_METHODS; // TEMP VARIABLE + unsigned int allow_methods = ANY_METHODS; // TEMP VARIABLE // after update in ConfigParser, use the "allow_methods" of location. - // TODO in ConfigParser : by default if no field in config file, "allow_methods" must be set to ALL_METHODS + // TODO in ConfigParser : by default if no field in config file, "allow_methods" must be set to ANY_METHODS if (client->get_method() == UNKNOWN) { - client->status = 400; + client->status = 501; } else if (allow_methods & client->get_method()) { switch (client->get_method()) { case (GET): - _get(client, server, location); - break; + _get(client, server, location); break; case (POST): - _post(client, server, location); - break; + _post(client, server, location); break; case (DELETE): - _delete(client, server, location); - break; + _delete(client, server, location); break; default: break; }