Merge branch 'master' of bitbucket.org:LuckyLaszlo/webserv

This commit is contained in:
Hugo LAMY
2022-08-14 01:09:25 +02:00
7 changed files with 46 additions and 37 deletions

View File

@@ -3,12 +3,13 @@
std::string Webserv::_replace_url_root(Client *client, std::string path)
{
std::cerr << "path before = " << path << "\n"; // DEBUG
std::cerr << "assigned_location->path = " << client->assigned_location->path << "\n"; // debug
std::cerr << "path before = " << path << "\n"; // DEBUG
if (client->assigned_location->path == "/")
path.insert(0, client->assigned_location->root);
else
path.replace(0, client->assigned_location->path.size(), client->assigned_location->root);
std::cerr << "path after = " << path << "\n"; // DEBUG
std::cerr << "path after = " << path << "\n"; // DEBUG
return path;
}
@@ -20,7 +21,6 @@ void Webserv::_get(Client *client, std::string &path)
// Index/Autoindex block
if (eval_file_type(path) == IS_DIR)
{
std::cout << "made it to Index/Autoindex\n";
if (path[path.size() - 1] != '/')
path.push_back('/');
for (size_t i = 0; i < client->assigned_location->index.size(); i++)
@@ -50,7 +50,7 @@ void Webserv::_get_file(Client *client, const std::string &path)
std::ifstream ifd; // For chunk, ifstream directly in struct CLient for multiples read without close() ?
std::stringstream buf;
std::cout << "made it to get_file\n";
std::cout << "_get_file()\n";
if (access(path.c_str(), F_OK) == -1)
{
@@ -103,16 +103,15 @@ void Webserv::_get_file(Client *client, const std::string &path)
// const?
void Webserv::_autoindex(Client *client, const std::string &path)
{
std::cout << "made it to _autoindex\n";
std::cout << "_autoindex()\n";
std::string dir_list;
DIR *dir;
struct dirent *ent;
std::cout << "location root: " << client->assigned_location->root << " location path: "
<< client->assigned_location->path << '\n';
// std::cout << "location root: " << client->assigned_location->root << " location path: " << client->assigned_location->path << '\n';
std::cout << "Path in auto is: " << path << '\n';
// std::cout << "Path in auto is: " << path << '\n';
if ( (dir = opendir(path.c_str()) ) != NULL)
{
dir_list.append(AUTOINDEX_START);
@@ -123,11 +122,11 @@ void Webserv::_autoindex(Client *client, const std::string &path)
/* print all the files and directories within directory */
while ((ent = readdir (dir)) != NULL)
{
std::cout << "ent: " << ent->d_name << '\n';
// std::cout << "ent: " << ent->d_name << '\n';
if (strcmp(".", ent->d_name) == 0)
continue ;
dir_list.append("<a href=\"");
dir_list.append(client->assigned_location->path + "/");
dir_list.append(client->get_rq_abs_path() + "/");
dir_list.append(ent->d_name);
dir_list.append("\">");
dir_list.append(ent->d_name);

View File

@@ -37,7 +37,6 @@ int Webserv::_read_request(Client *client)
char buf[BUFSIZE];
ssize_t ret;
std::cerr << "call recv()" << "\n" ;
ret = ::recv(client->get_cl_fd(), buf, BUFSIZE, 0);
std::cerr << "recv() on fd(" << client->get_cl_fd() << ") returned = " << ret << "\n" ;
if (ret == -1)
@@ -51,6 +50,8 @@ int Webserv::_read_request(Client *client)
return READ_CLOSE;
}
client->raw_request.append(buf, ret);
// ::print_special(client->raw_request);
// std::cerr << "__raw_request__\n" << client->raw_request << "\n______\n"; // DEBUG
if (!client->header_complete)
{
@@ -61,8 +62,7 @@ int Webserv::_read_request(Client *client)
{
if (client->get_rq_headers("Content-Type").empty()
&& client->get_rq_headers("Content-Length").empty()
// && client->get_rq_headers("Transfer-Encoding").empty()
)
&& client->get_rq_headers("Transfer-Encoding").empty())
return READ_COMPLETE; // No body case
}
else if (client->raw_request.size() > MAX_HEADER_SIZE)
@@ -71,7 +71,7 @@ int Webserv::_read_request(Client *client)
return READ_COMPLETE;
}
}
else if (client->header_complete)
if (client->header_complete)
{
// client->read_body_size += ret; // Not accurate, part of body could have been read with headers, unused for now
client->parse_request_body();

View File

@@ -88,8 +88,7 @@ void Webserv::_construct_response(Client *client)
void Webserv::_process_method(Client *client, std::string &path)
{
std::cerr << "assigned_location->path = " << client->assigned_location->path << "\n"; // debug
std::cerr << "allow_methods = " << client->assigned_location->allow_methods << "\n"; // debug
std::cerr << "allow_methods = " << http_methods_to_str(client->assigned_location->allow_methods) << "\n"; // debug
switch (client->get_rq_method())
{
@@ -185,8 +184,6 @@ ServerConfig *_determine_process_server(Client *client, std::vector<ServerConfig
// Temporary Global Scope. Probably move to Client in the future.
const LocationConfig *_determine_location(const ServerConfig &server, const std::string &path)
{
std::cout << "determin location path sent: " << path << '\n';
/* RULES ***
If a path coresponds exactly to a location, use that one
@@ -208,13 +205,8 @@ If we get a url that ends in / ignore the last /
for (std::vector<LocationConfig>::const_iterator it = server.locations.begin(); it != server.locations.end(); it++)
{
std::cout << it->path << " -- ";
if (it->path.size() > uri.size())
{
std::cout << "skipping this one\n";
continue ;
}
if (uri.compare(0, it->path.size(), it->path) == 0)
{