added http headers to readme

This commit is contained in:
hugogogo
2022-07-29 14:15:15 +02:00
parent 035dbe804d
commit 06ff3a4ea9
6 changed files with 273 additions and 18 deletions

View File

@@ -167,6 +167,12 @@ void Webserv::_read_request(Client *client)
buf[ret] = '\0';
client->raw_request.append(buf);
// HUGO TMP
//
_parse_request(client);
//
// HUGO TMP END
_epoll_update(client->fd, EPOLLOUT, EPOLL_CTL_MOD, client);
}
@@ -182,12 +188,14 @@ void Webserv::_send_response(Client *client)
// TMP HUGO test cgi
// if "POST" found in _buf, execve a cgi
if (std::string(_buf).find("POST") != std::string::npos)
_exec_cgi_script(fd);
// if "index.html" found in _buf, send the page
if (std::string(_buf).find("index.html") != std::string::npos)
_serve_file(fd, "index.html");
//
// if "POST" found in _buf, execve a cgi
if (client->raw_request.find("POST") != std::string::npos)
_exec_cgi_script(client);
// if "index.html" found in _buf, send the page
if (client->raw_request.find("index.html") != std::string::npos)
_serve_file(client, "index.html");
//
// TMP HUGO end test cgi
@@ -230,7 +238,14 @@ int Webserv::_epoll_update(int fd, uint32_t events, int op)
}
// TMP HUGO
void Webserv::_serve_file(int fd, std::string page)
//
void _parse_request(Client *client)
{
std::map<std::string, std::string> req = client->request;
req.insert();
}
void Webserv::_serve_file(Client *client, std::string page)
{
int page_fd;
std::string to_send;
@@ -252,10 +267,10 @@ void Webserv::_serve_file(int fd, std::string page)
to_send += strs.str();
to_send += end_header;
to_send += body;
if (::send(fd, to_send.c_str(), to_send.size(), 0) == -1)
if (::send(client->fd, to_send.c_str(), to_send.size(), 0) == -1)
std::perror("err send()");
}
void Webserv::_exec_cgi_script(int fd)
void Webserv::_exec_cgi_script(Client *client)
{
int save_stdout;
char** env = new char*[5];
@@ -272,7 +287,7 @@ void Webserv::_exec_cgi_script(int fd)
// inside child process
if (fork() == 0)
{
dup2(fd, STDOUT_FILENO);
dup2(client->fd, STDOUT_FILENO);
// execve("./srcs/cgi-bin/cgi_cpp.cgi", nll, env);
execve("./srcs/cgi-bin/php-cgi", nll, env);
}
@@ -282,6 +297,7 @@ void Webserv::_exec_cgi_script(int fd)
// restore stdout
dup2(save_stdout, STDOUT_FILENO);
}
//
// END TMP HUGO
int Webserv::_epoll_update(int fd, uint32_t events, int op, void *ptr)