Merge branch 'hugo5'
This commit is contained in:
@@ -24,7 +24,7 @@ int main (int ac, char **av, char ** env)
|
||||
path = get_value("file", rq_body);
|
||||
path = "./www/" + path;
|
||||
|
||||
status = ::eval_file_read(path);
|
||||
status = ::eval_file_access(path, R_OK);
|
||||
if (status)
|
||||
{
|
||||
std::cout << "Status: " << status << CRLF CRLF;
|
||||
|
||||
@@ -181,7 +181,7 @@ void
|
||||
http_body += HTML_BODY_BOTTOM;
|
||||
}
|
||||
|
||||
size_t eval_file_read(const std::string &path)
|
||||
size_t eval_file_access(const std::string &path, int mode)
|
||||
{
|
||||
if (::access(path.c_str(), F_OK) == -1)
|
||||
{
|
||||
@@ -189,7 +189,7 @@ size_t eval_file_read(const std::string &path)
|
||||
return 404; // NOT_FOUND, file doesn't exist
|
||||
}
|
||||
|
||||
if (::access(path.c_str(), R_OK) == -1)
|
||||
if (::access(path.c_str(), mode) == -1)
|
||||
{
|
||||
std::perror("err access()");
|
||||
return 403; // FORBIDDEN, file doesn't have access permission
|
||||
|
||||
@@ -62,7 +62,7 @@ void
|
||||
fill_body_basic(char **env, std::string & http_body, const std::string & rq_body);
|
||||
|
||||
size_t
|
||||
eval_file_read(const std::string &path);
|
||||
eval_file_access(const std::string &path, int mode);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -241,14 +241,15 @@ void Webserv::_check_script_output(Client *client, std::string & output)
|
||||
_check_script_status(client, output);
|
||||
if (client->status >= 400 && client->status < 600)
|
||||
return;
|
||||
//*DEBUG*/ std::cout << "\n" B_PURPLE "[script status]:" RESET "\n"; ::print_special(output); std::cout << B_PURPLE "-----------" RESET "\n\n";
|
||||
/*DEBUG*/ std::cout << "\n" B_PURPLE "[script status]:\n" << "client->status:[" << client->status << "]" RESET "\n"; ::print_special(output); std::cout << B_PURPLE "-----------" RESET "\n\n";
|
||||
client->status = _check_script_fields(output, client->status);
|
||||
/*DEBUG*/ std::cout << "\n" B_PURPLE "[script fields]:\n" << "client->status:[" << client->status << "]" RESET "\n"; ::print_special(output); std::cout << B_PURPLE "-----------" RESET "\n\n";
|
||||
_check_fields_duplicates(client, output);
|
||||
//*DEBUG*/ std::cout << "\n" B_PURPLE "[script fields]:" RESET "\n"; ::print_special(output); std::cout << B_PURPLE "-----------" RESET "\n\n";
|
||||
/*DEBUG*/ std::cout << "\n" B_PURPLE "[fields duplicates]:\n" << "client->status:[" << client->status << "]" RESET "\n"; ::print_special(output); std::cout << B_PURPLE "-----------" RESET "\n\n";
|
||||
_remove_body_leading_empty_lines(output);
|
||||
//*DEBUG*/ std::cout << "\n" B_PURPLE "[script empty lines]:" RESET "\n"; ::print_special(output); std::cout << B_PURPLE "-----------" RESET "\n\n";
|
||||
/*DEBUG*/ std::cout << "\n" B_PURPLE "[script empty lines]:\n" << "client->status:[" << client->status << "]" RESET "\n"; ::print_special(output); std::cout << B_PURPLE "-----------" RESET "\n\n";
|
||||
_add_script_body_length_header(output);
|
||||
//*DEBUG*/ std::cout << "\n" B_PURPLE "[script content length]:" RESET "\n"; ::print_special(output); std::cout << B_PURPLE "-----------" RESET "\n\n";
|
||||
/*DEBUG*/ std::cout << "\n" B_PURPLE "[script content length]:\n" << "client->status:[" << client->status << "]" RESET "\n"; ::print_special(output); std::cout << B_PURPLE "-----------" RESET "\n\n";
|
||||
}
|
||||
|
||||
void Webserv::_check_script_status(Client *client, std::string & output)
|
||||
@@ -273,9 +274,11 @@ size_t Webserv::_check_script_fields(const std::string & output, size_t status)
|
||||
std::string body;
|
||||
size_t pos;
|
||||
|
||||
std::cerr << "0\n";
|
||||
pos = output.find(CRLF CRLF);
|
||||
if (pos == NPOS) // there is not empty line
|
||||
return 500;
|
||||
std::cerr << "1\n";
|
||||
headers = output.substr(0, pos);
|
||||
body = output.substr(pos + CRLF_SIZE * 2);
|
||||
headers = str_tolower(headers);
|
||||
@@ -284,14 +287,18 @@ size_t Webserv::_check_script_fields(const std::string & output, size_t status)
|
||||
{
|
||||
if (!body.empty()) // there is body
|
||||
return 500;
|
||||
std::cerr << "2\n";
|
||||
if (headers.find("location") == NPOS) // there is no location field
|
||||
return 500;
|
||||
std::cerr << "3\n";
|
||||
}
|
||||
else if (headers.find("location") != NPOS) // there is a location field
|
||||
{
|
||||
if (body.empty()) // there is no body
|
||||
return 500;
|
||||
std::cerr << "4\n";
|
||||
}
|
||||
std::cerr << "5\n";
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@@ -52,12 +52,12 @@ int Webserv::_send_response(Client *client)
|
||||
}
|
||||
else if (!client->cgi_output.empty())
|
||||
{
|
||||
// /*DEBUG*/ std::cout << "\n" B_PURPLE "[response]:" RESET "\n"; ::print_special(client->response); std::cout << B_PURPLE "-----------" RESET "\n\n";
|
||||
// /*DEBUG*/ std::cout << "\n" B_PURPLE "[script output]:" RESET "\n"; ::print_special(script_output); std::cout << B_PURPLE "-----------" RESET "\n\n";
|
||||
/*DEBUG*/ std::cout << "\n" B_PURPLE "[response]:" RESET "\n"; ::print_special(client->response); std::cout << B_PURPLE "-----------" RESET "\n\n";
|
||||
/*DEBUG*/ std::cout << "\n" B_PURPLE "[script output]:" RESET "\n"; ::print_special(client->cgi_output); std::cout << B_PURPLE "-----------" RESET "\n\n";
|
||||
_check_script_output(client, client->cgi_output); // FD_CGI : adjust for client->cgi_output;
|
||||
if (client->status < 400)
|
||||
client->response += client->cgi_output;
|
||||
// /*DEBUG*/ std::cout << "\n" B_PURPLE "[response + output]:" RESET "\n"; ::print_special(client->response); std::cout << B_PURPLE "-----------" RESET "\n\n";
|
||||
/*DEBUG*/ std::cout << "\n" B_PURPLE "[response + output]:" RESET "\n"; ::print_special(client->response); std::cout << B_PURPLE "-----------" RESET "\n\n";
|
||||
}
|
||||
|
||||
_insert_status_line(client);
|
||||
@@ -201,3 +201,4 @@ void Webserv::_append_body(Client *client, const std::string &body, const std::s
|
||||
client->response.append(CRLF);
|
||||
client->response.append(body);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user