Browse Source

fix check_method

master
nicolas-arnaud 2 years ago
parent
commit
6c06b3e22f
  1. 10
      srcs/sock/Client.cpp
  2. 5
      srcs/webserv.cpp

10
srcs/sock/Client.cpp

@ -67,11 +67,13 @@ bool Client::check_method(Server *server, Route *route, string method) {
std::vector< string > allowed;
if (method != "GET" && method != "POST" && method != "DELETE")
send_error(405);
else if ((allowed = route->_headers).size() > 0) {
if (std::find(allowed.begin(), allowed.end(), method) == allowed.end())
else if ((allowed = route->_headers).size() > 0 &&
std::find(allowed.begin(), allowed.end(), method) ==
allowed.end()) {
send_error(405);
} else if ((allowed = server->_headers).size() > 0) {
if (std::find(allowed.begin(), allowed.end(), method) == allowed.end())
} else if ((allowed = server->_headers).size() > 0 &&
std::find(allowed.begin(), allowed.end(), method) ==
allowed.end()) {
send_error(405);
} else
return (true);

5
srcs/webserv.cpp

@ -12,7 +12,7 @@ int main(int ac, char **av) {
std::string config_file = "default.json";
if (ac == 2)
config_file = av[1];
std::ifstream file(config_file);
std::ifstream file(config_file.c_str());
if (!file.good())
throw std::runtime_error("File not found");
cout << "Parsing configuration file from JSON conf file.\n";
@ -23,8 +23,7 @@ int main(int ac, char **av) {
Env env(conf);
while (1)
env.cycle();
}
catch(const std::exception& e) {
} catch (const std::exception &e) {
std::cerr << e.what() << '\n';
}
return EXIT_SUCCESS;

Loading…
Cancel
Save