Skip to content

Commit

Permalink
tests(cgi): starting files to check non blocking behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
552020 committed May 18, 2024
1 parent 2cf1269 commit 05d4957
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 9 deletions.
19 changes: 19 additions & 0 deletions development.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
server {
listen 8080;
server_name www.development_site;
allow_methods GET POST DELETE;
autoindex off;
root /var/;
error_page 404 404.html;
cgi_ext .cgi;

location /admin {
return http://google.com;
index admin.html;
allow_methods GET POST;
}
location /cgi-bin/ {
cgi_ext .cgi .py;
autoindex off;
}
}
21 changes: 12 additions & 9 deletions src/Router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Router::Router()
{
}

Router::Router(Directives& directive) : _directive(directive), _FDsRef(NULL), _pollFd(NULL)
Router::Router(Directives &directive) : _directive(directive), _FDsRef(NULL), _pollFd(NULL)
{
}

Expand Down Expand Up @@ -55,7 +55,7 @@ void Router::adaptPathForFirefox(HTTPRequest &request)
void Router::routeRequest(HTTPRequest &request, HTTPResponse &response)
{
Debug::log("Routing Request: host = " + request.getSingleHeader("host").second, Debug::NORMAL);

if (!_directive._return.empty())
{
response.setStatusCode(301, "Redirection");
Expand Down Expand Up @@ -85,7 +85,7 @@ void Router::routeRequest(HTTPRequest &request, HTTPResponse &response)
case PathValid:
// check if method is allowed
if (!_directive._allowedMethods.empty())
{
{
for (size_t i = 0; i < _directive._allowedMethods.size(); i++)
{
if (_directive._allowedMethods[i] == request.getMethod())
Expand Down Expand Up @@ -229,6 +229,7 @@ bool Router::isCGI(const HTTPRequest &request)
std::cout << "request target: " << request.getRequestTarget() << std::endl;
if (!cgiExtensions.empty())
{
std::cout << "request target: " << request.getRequestTarget() << std::endl;
std::string fileExtension = getFileExtension(request.getRequestTarget());
std::cout << "fileExtension: " << fileExtension << std::endl;
for (size_t i = 0; i < cgiExtensions.size(); i++)
Expand Down Expand Up @@ -308,12 +309,14 @@ void Router::generateDirectoryListing(HTTPResponse &Response,
Response.setHeader("Content-Type", "text/html");
}

bool isDirectory(std::string& path) {
struct stat buffer;
if (stat(path.c_str(), &buffer) == 0) {
return S_ISDIR(buffer.st_mode);
}
return false; // Failed to get file information
bool isDirectory(std::string &path)
{
struct stat buffer;
if (stat(path.c_str(), &buffer) == 0)
{
return S_ISDIR(buffer.st_mode);
}
return false; // Failed to get file information
}

enum PathValidation Router::pathIsValid(HTTPResponse &response, HTTPRequest &request)
Expand Down
26 changes: 26 additions & 0 deletions var/www.development_site/cgi-bin/duration.cgi
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python3

import time
from datetime import datetime

# Define the duration of the counter in seconds
duration = 10

# Print the HTTP header
print("Content-Type: text/html")
print()

# Print the start time
start_time = datetime.now()
print(f"<html><body>")
print(f"<h1>Counter Script</h1>")
print(f"<p>Start time: {start_time}</p>")

# Counter loop
for i in range(duration):
time.sleep(1) # Wait for 1 second

# Print the end time
end_time = datetime.now()
print(f"<p>End time: {end_time}</p>")
print("</body></html>")
Empty file.

0 comments on commit 05d4957

Please sign in to comment.