diff --git a/htdocs/site-3/index.php b/htdocs/site-3/index.php
index f35a8ef..4ee9e65 100644
--- a/htdocs/site-3/index.php
+++ b/htdocs/site-3/index.php
@@ -1,3 +1,177 @@
+
+
+
+
+
+ CGI Capabilities Demo
+
+
+
+ 🚀 CGI Capabilities Demonstration
+
+
+ CGI Status: ✅ PHP CGI is working!
+ Execution Time:
+ PHP Version:
+
+
+
+
📊 Server Information
+
+ | Property | Value |
+ | Server Software | |
+ | Server Name | |
+ | Server Port | |
+ | Document Root | |
+ | Script Name | |
+ | Gateway Interface | |
+
+
+
+
+
🌐 HTTP Request Information
+
+ | Property | Value |
+ | Request Method | |
+ | Request URI | |
+ | Query String | |
+ | Content Type | |
+ | Content Length | |
+ | User Agent | |
+ | Remote Address | |
+ | Remote Host | |
+
+
+
+
+
🔧 CGI Environment Variables
+
+ | Variable | Value |
+ {$var} | " . htmlspecialchars($value) . " | ";
+ }
+ ?>
+
+
+
+
+
📝 Form Processing Demo
+
+
+
+
+ ✅ Form Submitted Successfully!
+ Name:
+ Message:
+ Submitted at:
+
+
+
+
+
+
🔍 Raw POST Data
+
+
+ Raw POST Data:
+
+
+
+
No POST data received. Submit the form above to see raw POST data.
+
+
+
+
+
⚡ Performance Test
+
+
✅ Computed square roots of numbers 0-99,999
+
Execution time: ms
+
Memory usage: KB
+
Peak memory: KB
+
+
+
+
📋 All Environment Variables
+
+ | Variable | Value |
+ $value) {
+ if (is_string($value)) {
+ echo "| " . htmlspecialchars($key) . " | " . htmlspecialchars($value) . " |
";
+ }
+ }
+ ?>
+
+
+
+
+
+
-phpinfo();
\ No newline at end of file
diff --git a/webserv/client/Client.cpp b/webserv/client/Client.cpp
index 527a6d2..c511d29 100644
--- a/webserv/client/Client.cpp
+++ b/webserv/client/Client.cpp
@@ -134,6 +134,8 @@ void Client::writeToCgi()
Log::debug("Wrote " + std::to_string(bytesWritten)
+ " bytes to CGI stdin, fd: " + std::to_string(cgiStdIn_->getFd()));
}
+ server_.remove(*cgiStdIn_);
+ cgiStdIn_ = nullptr;
}
void Client::readFromCgi()
@@ -156,13 +158,14 @@ void Client::readFromCgi()
Log::info("CGI process closed stdout, fd: " + std::to_string(cgiStdOut_->getFd()));
server_.remove(*cgiStdOut_);
cgiStdOut_ = nullptr;
+ httpResponse_->addHeader("Content-Type", "text/html");
+ httpResponse_->setComplete();
return;
}
else
{
buffer[bytesRead] = '\0'; // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
- httpResponse_->addHeader("Content-Type", "text/html");
- httpResponse_->setBody(std::string(buffer, static_cast(bytesRead)));
+ httpResponse_->appendBody(std::string(buffer, static_cast(bytesRead)));
Log::debug("Read " + std::to_string(bytesRead)
+ " bytes from CGI stdout, fd: " + std::to_string(cgiStdOut_->getFd()));
}
diff --git a/webserv/server/Server.cpp b/webserv/server/Server.cpp
index 4d79433..a57381d 100644
--- a/webserv/server/Server.cpp
+++ b/webserv/server/Server.cpp
@@ -164,7 +164,6 @@ void Server::handleRequest(struct epoll_event *event) const
Log::trace(LOCATION);
int client_fd = event->data.fd;
-
Client &client = getClient(client_fd);
client.getSocket(client_fd).callback();
}
@@ -192,14 +191,32 @@ void Server::handleResponse(struct epoll_event *event)
// disconnect(client);
}
+void Server::handleEpollHangUp(struct epoll_event *event)
+{
+ Client &client = getClient(event->data.fd);
+ ASocket &socket = client.getSocket(event->data.fd);
+ if (socket.getType() == ASocket::Type::CGI_SOCKET)
+ {
+ Log::info("CGI socket hang up on fd " + std::to_string(event->data.fd));
+ socket.callback();
+ return;
+ }
+ Log::warning("Epoll hang up on fd " + std::to_string(event->data.fd) + ": " + std::strerror(errno));
+}
+
void Server::handleEvent(struct epoll_event *event)
{
Log::trace(LOCATION);
- if ((event->events & EPOLLERR) > 0 || (event->events & EPOLLHUP) > 0)
+ if ((event->events & EPOLLERR) > 0)
{
Log::error("Epoll error on fd " + std::to_string(event->data.fd) + ": " + std::strerror(errno));
remove(getListener(event->data.fd));
close(event->data.fd);
+ return;
+ }
+ if ((event->events & EPOLLHUP) > 0)
+ {
+ handleEpollHangUp(event);
}
else if (listener_fds_.contains(event->data.fd))
{
@@ -217,7 +234,7 @@ void Server::handleEvent(struct epoll_event *event)
void Server::handleEpoll(struct epoll_event *events, int max_events)
{
- int nfds = epoll_wait(epoll_fd_, events, max_events, 0); // NOLINT
+ int nfds = epoll_wait(epoll_fd_, events, max_events, 10); // NOLINT
if (nfds == -1)
{
Log::error("epoll_wait failed");
@@ -247,6 +264,5 @@ void Server::run()
{
pollClients();
handleEpoll(events, MAX_EVENTS);
- // usleep(1000);
}
}
\ No newline at end of file
diff --git a/webserv/server/Server.hpp b/webserv/server/Server.hpp
index d47e773..79d48da 100644
--- a/webserv/server/Server.hpp
+++ b/webserv/server/Server.hpp
@@ -52,6 +52,7 @@ class Server
void pollClients() const;
void handleEpoll(struct epoll_event *events, int max_events);
+ void handleEpollHangUp(struct epoll_event *event);
void handleEvent(struct epoll_event *event);
void handleConnection(struct epoll_event *event);
void handleRequest(struct epoll_event *event) const;