works on download script
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user