ALL_METHODS renamed to ANY_METHODS
This commit is contained in:
@@ -17,7 +17,7 @@
|
|||||||
// GET = 0b00000001,
|
// GET = 0b00000001,
|
||||||
// POST = 0b00000010,
|
// POST = 0b00000010,
|
||||||
// DELETE = 0b00000100,
|
// DELETE = 0b00000100,
|
||||||
// ALL_METHODS = 0b11111111,
|
// ANY_METHODS = 0b11111111,
|
||||||
// };
|
// };
|
||||||
|
|
||||||
enum http_method
|
enum http_method
|
||||||
@@ -26,7 +26,7 @@ enum http_method
|
|||||||
GET = 1 << 0,
|
GET = 1 << 0,
|
||||||
POST = 1 << 1,
|
POST = 1 << 1,
|
||||||
DELETE = 1 << 2,
|
DELETE = 1 << 2,
|
||||||
ALL_METHODS = 0b11111111,
|
ANY_METHODS = 0b11111111,
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<std::string> split(std::string input, char delimiter);
|
std::vector<std::string> split(std::string input, char delimiter);
|
||||||
|
|||||||
@@ -37,5 +37,6 @@
|
|||||||
# define S413 "413 Content Too Large"
|
# define S413 "413 Content Too Large"
|
||||||
|
|
||||||
# define S500 "500 Internal Server Error"
|
# define S500 "500 Internal Server Error"
|
||||||
|
# define S501 "501 Not Implemented"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ void Webserv::_init_http_status_map()
|
|||||||
_http_status[413] = S413;
|
_http_status[413] = S413;
|
||||||
|
|
||||||
_http_status[500] = S500;
|
_http_status[500] = S500;
|
||||||
|
_http_status[501] = S501;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Webserv::_init_mime_types_map()
|
void Webserv::_init_mime_types_map()
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ void Webserv::_append_base_headers(Client *client)
|
|||||||
|
|
||||||
void Webserv::_construct_response(Client *client, ServerConfig &server)
|
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)
|
if (client->get_body().size() > server.client_body_limit)
|
||||||
{
|
{
|
||||||
client->status = 413;
|
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)
|
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.
|
// 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)
|
if (client->get_method() == UNKNOWN)
|
||||||
{
|
{
|
||||||
client->status = 400;
|
client->status = 501;
|
||||||
}
|
}
|
||||||
else if (allow_methods & client->get_method())
|
else if (allow_methods & client->get_method())
|
||||||
{
|
{
|
||||||
switch (client->get_method())
|
switch (client->get_method())
|
||||||
{
|
{
|
||||||
case (GET):
|
case (GET):
|
||||||
_get(client, server, location);
|
_get(client, server, location); break;
|
||||||
break;
|
|
||||||
case (POST):
|
case (POST):
|
||||||
_post(client, server, location);
|
_post(client, server, location); break;
|
||||||
break;
|
|
||||||
case (DELETE):
|
case (DELETE):
|
||||||
_delete(client, server, location);
|
_delete(client, server, location); break;
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user