fixed mistake in _read_request()
+ changes to some log output
This commit is contained in:
@@ -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,7 +122,7 @@ 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=\"");
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -85,8 +85,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())
|
||||
{
|
||||
@@ -182,8 +181,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
|
||||
@@ -205,13 +202,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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user