lots of log message and fixed bad_file_descriptor issue
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
# include <cerrno> // errno
|
||||
# include <unistd.h> // close, access
|
||||
# include <iostream> // cout, cin
|
||||
# include <iomanip> // setw
|
||||
# include <cstring> // memset
|
||||
# include <sys/socket.h> // socket, accept, listen, send, recv, bind, connect, setsockopt, getsockname
|
||||
# include <arpa/inet.h> // htonl, htons, ntohl, ntohs, inet_addr, inet_ntoa
|
||||
@@ -34,6 +35,7 @@
|
||||
# include "autoindex.hpp"
|
||||
# include "colors.h"
|
||||
|
||||
extern family_state family;
|
||||
extern bool g_run;
|
||||
extern int g_last_signal;
|
||||
void signal_handler(int signum);
|
||||
|
||||
@@ -8,7 +8,7 @@ void Webserv::_accept_connection(listen_socket &lsocket)
|
||||
int accepted_fd;
|
||||
std::map<std::string, std::string> infos;
|
||||
|
||||
std::cerr << "accept()\n";
|
||||
std::cerr << family << "| " << " accept() socket (" << lsocket.fd << ")\n";
|
||||
addr_len = sizeof addr;
|
||||
accepted_fd = ::accept(lsocket.fd, (sockaddr*)&addr, &addr_len);
|
||||
if (accepted_fd == -1)
|
||||
|
||||
@@ -12,9 +12,11 @@ bool Webserv::_is_cgi(Client *client, std::string path)
|
||||
size_t file_access = client->status;
|
||||
size_t pos = 0;
|
||||
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") ....._is_cgi()\n";
|
||||
while (pos != NPOS)
|
||||
{
|
||||
pos = _cgi_pos(client, path, pos);
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") ....>_is_cgi()\n";
|
||||
if (pos == NPOS)
|
||||
break;
|
||||
client->fill_script_path(path, pos);
|
||||
@@ -42,6 +44,7 @@ size_t Webserv::_cgi_pos(Client *client, std::string &path, size_t pos)
|
||||
size_t len;
|
||||
std::locale loc; // for isalpha()
|
||||
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") ....._cgi_pos()\n";
|
||||
v_ext = client->assigned_location->cgi_ext;
|
||||
if (v_ext.empty())
|
||||
return NPOS;
|
||||
@@ -72,13 +75,16 @@ void Webserv::_cgi_open_pipes(Client *client)
|
||||
#define W 1
|
||||
int pipe_fd[2];
|
||||
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") ....._cgi_open_pipes()\n";
|
||||
if (::pipe(pipe_fd) == -1)
|
||||
{
|
||||
std::perror("err pipe");
|
||||
client->status = 500;
|
||||
}
|
||||
client->cgi_pipe_r_from_parent = pipe_fd[R];
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") open pipe rfp [" << client->cgi_pipe_r_from_parent << "]\n";
|
||||
client->cgi_pipe_w_to_child = pipe_fd[W];
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") open pipe wtc [" << client->cgi_pipe_w_to_child << "]\n";
|
||||
|
||||
if (::pipe(pipe_fd) == -1)
|
||||
{
|
||||
@@ -90,7 +96,9 @@ void Webserv::_cgi_open_pipes(Client *client)
|
||||
client->status = 500;
|
||||
}
|
||||
client->cgi_pipe_r_from_child = pipe_fd[R];
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") open pipe rfc [" << client->cgi_pipe_r_from_child << "]\n";
|
||||
client->cgi_pipe_w_to_parent = pipe_fd[W];
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") open pipe wtp [" << client->cgi_pipe_w_to_parent << "]\n";
|
||||
|
||||
// epoll add for writing body to child
|
||||
_epoll_update(client->cgi_pipe_w_to_child, EPOLLOUT, EPOLL_CTL_ADD);
|
||||
@@ -104,6 +112,7 @@ void Webserv::_write_body_to_cgi(Client *client)
|
||||
ssize_t ret;
|
||||
std::string body = client->get_rq_body();
|
||||
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") ....._write_body_to_cgi()\n";
|
||||
ret = ::write(client->cgi_pipe_w_to_child, body.c_str(), body.size());
|
||||
if (ret == -1)
|
||||
{
|
||||
@@ -121,6 +130,7 @@ void Webserv::_exec_cgi(Client *client)
|
||||
env_vector.reserve(18);
|
||||
int i = 0;
|
||||
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") ....._exec_cgi()\n";
|
||||
_set_env_vector(client, env_vector);
|
||||
try {
|
||||
_set_env_cstr(env_cstr, env_vector);
|
||||
@@ -161,6 +171,7 @@ std::string Webserv::_dup_env(std::string var, int i)
|
||||
*/
|
||||
void Webserv::_set_env_vector(Client *client, std::vector<std::string> &env_vector)
|
||||
{
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") ....._set_env_vector()\n";
|
||||
env_vector.push_back(_dup_env("AUTH_TYPE")); // authentification not supported
|
||||
env_vector.push_back(_dup_env("CONTENT_LENGTH" , client->get_rq_body().size()));
|
||||
env_vector.push_back(_dup_env("CONTENT_TYPE" , client->get_rq_headers("Content-Type")));
|
||||
@@ -186,6 +197,7 @@ void Webserv::_set_env_cstr(char *env_cstr[], std::vector<std::string> &env_vect
|
||||
std::vector<std::string>::const_iterator it = env_vector.begin();
|
||||
std::vector<std::string>::const_iterator it_end = env_vector.end();
|
||||
int i = 0;
|
||||
|
||||
while (it != it_end)
|
||||
{
|
||||
env_cstr[i] = new char[it->size()+1];
|
||||
@@ -203,10 +215,10 @@ void Webserv::_exec_script(Client *client, char *env[])
|
||||
char * const nll[1] = {NULL};
|
||||
std::string path;
|
||||
|
||||
std::cerr << "_exec_script() client " << client->get_cl_fd() << "\n";
|
||||
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") ....._exec_script()\n";
|
||||
// pid = 1; // DEBUG, if no fork, no problem
|
||||
pid = fork();
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") fork()\n";
|
||||
if (pid == -1)
|
||||
{
|
||||
std::perror("err fork()");
|
||||
@@ -217,6 +229,7 @@ void Webserv::_exec_script(Client *client, char *env[])
|
||||
{
|
||||
std::signal(SIGPIPE, SIG_DFL);
|
||||
std::signal(SIGINT, SIG_DFL);
|
||||
family = CHILD;
|
||||
|
||||
if (dup2(client->cgi_pipe_r_from_parent, STDIN_FILENO) == -1)
|
||||
{
|
||||
@@ -234,7 +247,7 @@ void Webserv::_exec_script(Client *client, char *env[])
|
||||
_close_all_clients_fd();
|
||||
|
||||
path = client->get_rq_script_path();
|
||||
std::cerr << "execve:[" << path << "]\n"; // DEBUG
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") execve:[" << path << "]\n"; // DEBUG
|
||||
if (::execve(path.c_str(), nll, env) == -1) // replace path for debug error forcing
|
||||
{
|
||||
std::perror("err execve()");
|
||||
@@ -247,12 +260,23 @@ void Webserv::_exec_script(Client *client, char *env[])
|
||||
}
|
||||
else //parent
|
||||
{
|
||||
usleep(1 * 1000);
|
||||
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") close pipe rfp [" << client->cgi_pipe_r_from_parent << "]\n";
|
||||
if (::close(client->cgi_pipe_r_from_parent) == -1)
|
||||
std::perror("err close");
|
||||
client->cgi_pipe_r_from_parent = -1;
|
||||
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") close pipe wtp [" << client->cgi_pipe_w_to_parent << "]\n";
|
||||
if (::close(client->cgi_pipe_w_to_parent) == -1)
|
||||
std::perror("err close");
|
||||
client->cgi_pipe_w_to_parent = -1;
|
||||
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") close pipe wtc [" << client->cgi_pipe_w_to_child << "]\n";
|
||||
if (::close(client->cgi_pipe_w_to_child) == -1)
|
||||
std::perror("err close");
|
||||
client->cgi_pipe_w_to_child = -1;
|
||||
|
||||
// add client->cgi_pipe_r_from_child to epoll,
|
||||
_epoll_update(client->cgi_pipe_r_from_child, EPOLLIN, EPOLL_CTL_ADD);
|
||||
// stop monitoring client->fd until the cgi-script as done is job
|
||||
@@ -269,6 +293,8 @@ void Webserv::_check_script_output(Client *client, std::string & output)
|
||||
{
|
||||
size_t pos;
|
||||
pos = client->cgi_output.find(CRLF CRLF);
|
||||
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") ....._check_script_output()\n";
|
||||
if (pos == 0 || pos == NPOS)
|
||||
{
|
||||
client->status = 500;;
|
||||
@@ -288,6 +314,7 @@ void Webserv::_check_script_status(Client *client, std::string & output)
|
||||
size_t pos;
|
||||
int status_pos;
|
||||
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") ....._check_script_status()\n";
|
||||
pos = output.find("Status:");
|
||||
if (pos != NPOS)
|
||||
{
|
||||
@@ -305,7 +332,6 @@ unsigned int Webserv::_check_script_fields(const std::string & output, unsigned
|
||||
std::string body;
|
||||
size_t pos;
|
||||
|
||||
std::cerr << "_check_script_fields()\n";
|
||||
pos = output.find(CRLF CRLF);
|
||||
if (pos == NPOS) // there is not empty line
|
||||
return 500;
|
||||
@@ -337,6 +363,7 @@ void Webserv::_check_fields_duplicates(Client *client, std::string & output)
|
||||
std::string tmp;
|
||||
size_t pos;
|
||||
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") ....._check_fields_duplicates()\n";
|
||||
// put server headers in map
|
||||
tmp = client->response;
|
||||
pos = tmp.find(CRLF CRLF);
|
||||
|
||||
@@ -34,9 +34,12 @@ void Webserv::_handle_epollerr_cgi_output(uint32_t events, Client *client)
|
||||
if (wait_ret == client->cgi_pid)
|
||||
{
|
||||
_epoll_update(client->cgi_pipe_r_from_child, 0, EPOLL_CTL_DEL);
|
||||
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") close pipe rfc [" << client->cgi_pipe_r_from_child << "]\n";
|
||||
if (::close(client->cgi_pipe_r_from_child) == -1)
|
||||
std::perror("err close()");
|
||||
client->cgi_pipe_r_from_child = -1;
|
||||
|
||||
_epoll_update(client->get_cl_fd(), EPOLLOUT, EPOLL_CTL_ADD);
|
||||
}
|
||||
|
||||
@@ -52,9 +55,12 @@ void Webserv::_handle_epollhup_cgi_output(uint32_t events, Client *client)
|
||||
if (wait_ret == client->cgi_pid)
|
||||
{
|
||||
_epoll_update(client->cgi_pipe_r_from_child, 0, EPOLL_CTL_DEL);
|
||||
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") close pipe rfc [" << client->cgi_pipe_r_from_child << "]\n";
|
||||
if (::close(client->cgi_pipe_r_from_child) == -1)
|
||||
std::perror("err close()");
|
||||
client->cgi_pipe_r_from_child = -1;
|
||||
|
||||
_epoll_update(client->get_cl_fd(), EPOLLOUT, EPOLL_CTL_ADD);
|
||||
client->cgi_state = CGI_OUTPUT_COMPLETE;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ void Webserv::_close_client(int fd)
|
||||
{
|
||||
if (*it == fd)
|
||||
{
|
||||
std::cerr << "close client fd " << fd << "\n";
|
||||
std::cout << family << "| (" << std::setw(2) << it->get_cl_fd() << ") close client fd " << fd << std::endl;
|
||||
if (::close(fd) == -1)
|
||||
std::perror("err close()");
|
||||
_close_client_cgi_pipes(&(*it));
|
||||
@@ -24,21 +24,28 @@ void Webserv::_close_client_cgi_pipes(Client *client)
|
||||
{
|
||||
if (client->cgi_state)
|
||||
{ // No need to reset the fd to -1 normaly
|
||||
std::cerr << "close cgi-pipes" << "\n";
|
||||
if (::close(client->cgi_pipe_w_to_child) == -1)
|
||||
std::perror("err close()");
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") close pipe wtc [" << client->cgi_pipe_w_to_child << "]\n";
|
||||
if (client->cgi_pipe_w_to_child != -1)
|
||||
if (::close(client->cgi_pipe_w_to_child) == -1)
|
||||
std::perror("err close()");
|
||||
client->cgi_pipe_w_to_child = -1;
|
||||
|
||||
if (::close(client->cgi_pipe_r_from_child) == -1)
|
||||
std::perror("err close()");
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") close pipe rfc [" << client->cgi_pipe_r_from_child << "]\n";
|
||||
if (client->cgi_pipe_r_from_child != -1)
|
||||
if (::close(client->cgi_pipe_r_from_child) == -1)
|
||||
std::perror("err close()");
|
||||
client->cgi_pipe_r_from_child = -1;
|
||||
|
||||
if (::close(client->cgi_pipe_w_to_parent) == -1)
|
||||
std::perror("err close()");
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") close pipe wtp [" << client->cgi_pipe_w_to_parent << "]\n";
|
||||
if (client->cgi_pipe_w_to_parent != -1)
|
||||
if (::close(client->cgi_pipe_w_to_parent) == -1)
|
||||
std::perror("err close()");
|
||||
client->cgi_pipe_w_to_parent = -1;
|
||||
|
||||
if (::close(client->cgi_pipe_r_from_parent) == -1)
|
||||
std::perror("err close()");
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") close pipe rfp [" << client->cgi_pipe_r_from_parent << "]\n";
|
||||
if (client->cgi_pipe_r_from_parent != -1)
|
||||
if (::close(client->cgi_pipe_r_from_parent) == -1)
|
||||
std::perror("err close()");
|
||||
client->cgi_pipe_r_from_parent = -1;
|
||||
}
|
||||
}
|
||||
@@ -56,7 +63,7 @@ void Webserv::_close_all_clients_fd()
|
||||
std::vector<Client>::iterator it_end = _clients.end();
|
||||
while (it != it_end)
|
||||
{
|
||||
std::cerr << "close client fd " << it->get_cl_fd() << "\n";
|
||||
std::cout << family << "| (" << std::setw(2) << it->get_cl_fd() << ") close client fd " << it->get_cl_fd() << std::endl;
|
||||
if (::close(it->get_cl_fd()) == -1)
|
||||
std::perror("err close()");
|
||||
++it;
|
||||
|
||||
@@ -11,7 +11,7 @@ void Webserv::_delete(Client *client, const std::string &path)
|
||||
|
||||
void Webserv::_delete_file(Client *client, const std::string &path)
|
||||
{
|
||||
std::cout << "_delete_file()\n";
|
||||
std::cerr << "_delete_file()\n";
|
||||
client->status = ::eval_file_access(path, W_OK);
|
||||
if (client->status)
|
||||
return;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*/
|
||||
void Webserv::_get(Client *client, std::string &path)
|
||||
{
|
||||
std::cout << "_get()\n";
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") _get()\n"; // debug
|
||||
if (eval_file_type(path) == IS_DIR)
|
||||
{
|
||||
if (path[path.size() - 1] != '/')
|
||||
@@ -18,7 +18,7 @@ void Webserv::_get(Client *client, std::string &path)
|
||||
{
|
||||
path.append(client->assigned_location->index[i]);
|
||||
_get_file(client, path);
|
||||
std::cerr << "Added an index\n"; //debug
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") Added an index\n"; //debug
|
||||
return ;
|
||||
}
|
||||
}
|
||||
@@ -41,8 +41,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 << "_get_file()\n";
|
||||
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") _get_file()\n";
|
||||
client->status = ::eval_file_access(path, R_OK);
|
||||
if (client->status)
|
||||
return;
|
||||
@@ -90,7 +89,7 @@ if (size > MAX_FILESIZE)
|
||||
*/
|
||||
void Webserv::_autoindex(Client *client, const std::string &path)
|
||||
{
|
||||
std::cout << "_autoindex()\n";
|
||||
std::cerr << "_autoindex()\n";
|
||||
|
||||
std::string dir_list;
|
||||
DIR *dir;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
void Webserv::_post(Client *client, const std::string &path)
|
||||
{
|
||||
(void)path; // unused, we use "assigned_location->upload_dir" instead
|
||||
std::cout << "_post()\n";
|
||||
std::cerr << "_post()\n";
|
||||
|
||||
if (client->get_rq_abs_path() != client->assigned_location->path)
|
||||
client->status = 404; // 404 or other status better ?
|
||||
@@ -27,7 +27,7 @@ void Webserv::_post(Client *client, const std::string &path)
|
||||
#define DEFAULT_NAME "unnamed_file"
|
||||
void Webserv::_upload_files(Client *client)
|
||||
{
|
||||
std::cout << "_upload_files()\n";
|
||||
std::cerr << "_upload_files()\n";
|
||||
std::ofstream ofd;
|
||||
std::vector<MultipartBody>::const_iterator body_it = client->get_rq_multi_bodys().begin();
|
||||
std::string path;
|
||||
|
||||
@@ -36,7 +36,7 @@ int Webserv::_read_request(Client *client)
|
||||
ssize_t ret;
|
||||
|
||||
ret = ::recv(client->get_cl_fd(), buf, BUFSIZE, 0);
|
||||
std::cerr << "recv() on fd(" << client->get_cl_fd() << ") ret = " << ret << "\n" ;
|
||||
std::cout << family << "| (" << std::setw(2) << client->get_cl_fd() << ") recv() ret = " << ret << std::endl;
|
||||
if (ret == -1)
|
||||
{
|
||||
std::perror("err recv()");
|
||||
|
||||
@@ -12,6 +12,7 @@ void Webserv::_response(Client *client)
|
||||
{
|
||||
int ret = _send_response(client);
|
||||
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") ....._response()\n";
|
||||
if (g_last_signal)
|
||||
_handle_last_signal();
|
||||
|
||||
@@ -38,10 +39,12 @@ int Webserv::_send_response(Client *client)
|
||||
{
|
||||
ssize_t ret;
|
||||
|
||||
std::cerr << "send()\n";
|
||||
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") ....._send_response()\n";
|
||||
if (client->response.empty())
|
||||
{
|
||||
_append_base_headers(client);
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") ....>_send_response()\n";
|
||||
}
|
||||
|
||||
if (!client->status)
|
||||
{
|
||||
@@ -49,12 +52,18 @@ int Webserv::_send_response(Client *client)
|
||||
if (client->cgi_state == CGI_WAIT_TO_EXEC
|
||||
|| client->cgi_state == CGI_OUTPUT_READING)
|
||||
return SEND_IN_PROGRESS;
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") ....>_send_response()\n";
|
||||
}
|
||||
|
||||
_insert_status_line(client);
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") ....>_send_response()\n";
|
||||
if (client->status >= 400)
|
||||
{
|
||||
_error_html_response(client);
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") ....>_send_response()\n";
|
||||
}
|
||||
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") send()\n"; // Debug
|
||||
ret = ::send(client->get_cl_fd(), client->response.c_str(), client->response.size(), 0);
|
||||
if (ret == -1)
|
||||
{
|
||||
@@ -74,6 +83,7 @@ void Webserv::_append_base_headers(Client *client)
|
||||
{
|
||||
client->response.append("Server: Webserv/0.1" CRLF);
|
||||
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") ....._append_base_headers()\n";
|
||||
if (client->get_rq_headers("Connection") == "close"
|
||||
|| client->status == 400
|
||||
|| client->status == 408
|
||||
@@ -88,10 +98,13 @@ void Webserv::_construct_response(Client *client)
|
||||
std::string path;
|
||||
std::string script_output;
|
||||
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") ....._construct_response()\n";
|
||||
path = _replace_url_root(client, client->get_rq_abs_path());
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") ....>_construct_response()\n";
|
||||
if (client->cgi_state == CGI_READY_TO_EXEC)
|
||||
{
|
||||
_write_body_to_cgi(client);
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") ....>_construct_response()\n";
|
||||
if (client->status)
|
||||
return;
|
||||
_exec_cgi(client);
|
||||
@@ -99,6 +112,7 @@ void Webserv::_construct_response(Client *client)
|
||||
else if (client->cgi_state == CGI_OUTPUT_COMPLETE)
|
||||
{
|
||||
_check_script_output(client, client->cgi_output);
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") ....>_construct_response()\n";
|
||||
if (client->status < 400 || client->status >= 600)
|
||||
client->response += client->cgi_output;
|
||||
}
|
||||
@@ -110,6 +124,7 @@ void Webserv::_construct_response(Client *client)
|
||||
|
||||
void Webserv::_process_method(Client *client, std::string &path)
|
||||
{
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") ....._process_method()\n";
|
||||
switch (client->get_rq_method())
|
||||
{
|
||||
case (GET):
|
||||
@@ -125,6 +140,7 @@ void Webserv::_process_method(Client *client, std::string &path)
|
||||
|
||||
std::string Webserv::_replace_url_root(Client *client, std::string path)
|
||||
{
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") ....._replace_url_root()\n";
|
||||
if (client->assigned_location->path == "/")
|
||||
path.insert(0, client->assigned_location->root);
|
||||
else
|
||||
@@ -139,6 +155,8 @@ void Webserv::_insert_status_line(Client *client)
|
||||
{
|
||||
std::string status_line;
|
||||
std::string status = _http_status[client->status];
|
||||
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") ....._insert_status_line()\n";
|
||||
if (status.empty())
|
||||
status = ::itos(client->status);
|
||||
|
||||
@@ -150,8 +168,9 @@ void Webserv::_insert_status_line(Client *client)
|
||||
|
||||
void Webserv::_error_html_response(Client *client)
|
||||
{
|
||||
std::cout << "_error_html_response()\n";
|
||||
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") ....._error_html_response()\n";
|
||||
std::cerr << "_error_html_response()\n";
|
||||
if (client->assigned_server
|
||||
&& !client->assigned_server->error_pages[client->status].empty()
|
||||
&& ::eval_file_access(client->assigned_server->error_pages[client->status], R_OK) == 0 )
|
||||
@@ -165,6 +184,7 @@ void Webserv::_error_html_response(Client *client)
|
||||
status = "Error " + ::itos(client->status);
|
||||
std::string html_page = HTML_ERROR;
|
||||
::replace_all_substr(html_page, STATUS_PLACEHOLDER, status);
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") ....>_error_html_response()\n";
|
||||
_append_body(client, html_page, "html");
|
||||
}
|
||||
}
|
||||
@@ -173,6 +193,7 @@ void Webserv::_append_body(Client *client, const std::string &body, const std::s
|
||||
{
|
||||
const std::string &mime_type = _mime_types[file_extension];
|
||||
|
||||
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") ....._append_body()\n";
|
||||
client->response.append("Content-Type: ");
|
||||
if (mime_type.empty())
|
||||
client->response.append(MIME_TYPE_DEFAULT);
|
||||
|
||||
@@ -19,11 +19,12 @@ void Webserv::run()
|
||||
std::signal(SIGPIPE, signal_handler);
|
||||
std::signal(SIGINT, signal_handler);
|
||||
g_run = true;
|
||||
family = PARENT;
|
||||
while (g_run)
|
||||
{
|
||||
std::cerr << ++count_loop << "----loop epoll() ";
|
||||
std::cout << family << "|" << ++count_loop << "-----loop epoll() ";
|
||||
nfds = ::epoll_wait(_epfd, events, MAX_EVENTS, TIMEOUT);
|
||||
std::cerr << "(nfds=" << nfds << ")\n";
|
||||
std::cerr << "(nfds=" << nfds << ")" << std::endl;
|
||||
if (nfds == -1)
|
||||
{
|
||||
int errno_copy = errno;
|
||||
|
||||
Reference in New Issue
Block a user