Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion conf/default.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
server {
listen 0.0.0.0:8001;
listen 0.0.0.0:8000;
server_name localhost;
root ./;
autoindex on;
Expand Down
9 changes: 1 addition & 8 deletions src/Cgi/Cgi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ static int getVectors(ServerConf server, std::vector<std::string>& ext,

for (std::vector<LocationConf>::const_iterator it = locations.begin();
it != locations.end(); ++it) {
//std::cerr << "Location Path: " << it->getPath() << ", Root Dir: " << it->getRootDir() << std::endl;

std::string Compare_dir = it->getPath();

Expand Down Expand Up @@ -127,10 +126,8 @@ static int checkFile( HttpRequest& req, std::string& interpreter ){
pathIt++;
}
if( interpreter.empty() ){
//std::cerr << "DEBUG: No interpreter found for file extension " << end << std::endl;
return( 500);
}
//std::cerr << "DEBUG: Interpreter for " << uri << " is " << interpreter << std::endl;
return( 200 );
}

Expand Down Expand Up @@ -328,17 +325,13 @@ static int parentProcess( HttpRequest& req, int* inputPipe, int* outputPipe, pid

while (bytesWritten < totalBytes) {
ssize_t result = write(inputPipe[1], data + bytesWritten, totalBytes - bytesWritten);
//std::cerr << "DEBUG: Write result: " << result << " bytes" << std::endl;

if (result <= 0) {
//std::cerr << "DEBUG: Write error: " << strerror(errno) << std::endl;
// Handle error
break;
}
bytesWritten += result;
}

//std::cerr << "DEBUG: Total bytes written: " << bytesWritten << "/" << totalBytes << std::endl;

// Add a small delay to ensure data is transferred before closing pipe
usleep(5000); // 1ms delay
Expand Down Expand Up @@ -378,7 +371,7 @@ static int parentProcess( HttpRequest& req, int* inputPipe, int* outputPipe, pid

//if return == TIMEOUT
else if( pollRet == 0 || ( startTime - time( NULL ) ) > TIMEOUT_TIME ){
std::cout << BLUE << "INFO: Cgi: Timeout" << END << std::endl;
std::cout << BLUE << "INFO: Cgi: Timeout" << END << '\n';
close( outputPipe[0] );
kill( pid, SIGKILL );
waitpid( pid, &status, 0 );
Expand Down
20 changes: 10 additions & 10 deletions src/Config/LocationConf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ std::ostream& operator <<( std::ostream& os, const LocationConf& loc ) {

// Print path
if ( !loc.getPath().empty() ){
os << "Path: " << loc.getPath() << std::endl;
os << "Path: " << loc.getPath() << '\n';
}

// Print allowed methods
Expand All @@ -57,27 +57,27 @@ std::ostream& operator <<( std::ostream& os, const LocationConf& loc ) {
it != tmp.end(); ++it) {
os << *it << " ";
}
os << std::endl;
os << '\n';
}

// Print allowed redirects
if ( !loc.getAllowedRedirects().empty() ){
os << "Allowed Redirects:" << std::endl;
os << "Allowed Redirects:" << '\n';
std::map< std::string, std::string > tmp2 = loc.getAllowedRedirects();
for (std::map<std::string, std::string>::const_iterator it = tmp2.begin();
it != tmp2.end(); ++it) {
os << " Code " << it->first << ": " << it->second << std::endl;
os << " Code " << it->first << ": " << it->second << '\n';
}
}

// Print root directory
if ( !loc.getRootDir().empty() ){
os << "Root Directory: " << loc.getRootDir() << std::endl;
os << "Root Directory: " << loc.getRootDir() << '\n';
}

// Print auto index setting
if ( loc.getAutoIndex() == true ){
os << "Auto Index: " << "On" << std::endl;
os << "Auto Index: " << "On" << '\n';
}

// Print index files
Expand All @@ -88,7 +88,7 @@ std::ostream& operator <<( std::ostream& os, const LocationConf& loc ) {
it != tmp.end(); ++it) {
os << *it << " ";
}
os << std::endl;
os << '\n';
}

// Print CGI paths
Expand All @@ -99,7 +99,7 @@ std::ostream& operator <<( std::ostream& os, const LocationConf& loc ) {
it != tmp.end(); ++it) {
os << *it << " ";
}
os << std::endl;
os << '\n';
}

// Print CGI extensions
Expand All @@ -110,12 +110,12 @@ std::ostream& operator <<( std::ostream& os, const LocationConf& loc ) {
it != tmp.end(); ++it) {
os << *it << " ";
}
os << std::endl;
os << '\n';
}

// Print upload directory
if ( !loc.getUploadDir().empty() ){
os << "Upload Directory: " << loc.getUploadDir() << std::endl;
os << "Upload Directory: " << loc.getUploadDir() << '\n';
}

return os;
Expand Down
4 changes: 2 additions & 2 deletions src/Config/ServerConf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ ServerConf& ServerConf::operator =( const ServerConf& og ) {

std::ostream& operator <<( std::ostream& os, const ServerConf& server) {

os << "ServerConf Details:\n" << std::endl;
os << "ServerConf Details:" << '\n';
std::vector< std::string > tmp;

// Print IP and Port
Expand Down Expand Up @@ -96,7 +96,7 @@ std::ostream& operator <<( std::ostream& os, const ServerConf& server) {
it != tmp.end(); ++it) {
os << *it << " ";
}
os << std::endl;
os << '\n';
}

// Print LocationConfs
Expand Down
7 changes: 2 additions & 5 deletions src/Http/HttpRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,7 @@ void HttpRequest::parseBody(const std::string& rawRequest) {
if (bodyStart + contentLength <= rawRequest.length()) {
std::string bodyContent = rawRequest.substr(bodyStart, contentLength);
setBody(bodyContent);

// Debug output
// std::cout << "Read POST body, length: " << bodyContent.length() << std::endl;

} else {
std::cerr << "Warning: Incomplete body received. Expected "
<< contentLength << " bytes, got "
Expand Down Expand Up @@ -381,7 +379,6 @@ void HttpRequest::validateRequestPath(void) {

// Protect against empty/null values
if (_server.getRootDir().empty()) {
// std::cout << "Warning: Server root is empty" << std::endl;
_response_code = 500;
return;
}
Expand Down Expand Up @@ -410,7 +407,7 @@ void HttpRequest::validateRequestPath(void) {
locationPath += it->getIndex()[0];
_pathInfo = PathInfo(locationPath);
} else {
std::cout << "Warning: Location has no index files" << std::endl;
std::cout << "Warning: Location has no index files" << '\n';
_response_code = 404;
return;
}
Expand Down
40 changes: 0 additions & 40 deletions src/Http/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,6 @@ int main(int argc, char *argv[]) {
return( 1 );
}

// // ALEC TESTING
// FILE* file = fopen("assets/get.example", "r");
// if (!file) {
// std::cerr << "Failed to open the file." << std::endl;
// return 1;
// }
// int fd = fileno(file);
// HttpRequest request(fd, config);
// request.parse();
// std::cout << request << std::endl;
// fclose(file);

// Parse Config File
try {
config.parse( confFile );
Expand All @@ -49,33 +37,5 @@ int main(int argc, char *argv[]) {
return( 1 );
}










// *** TESTING PARSER
//std::vector< ServerConf > tmp = config.getServerConfs();
//for( std::vector< ServerConf >::const_iterator it = tmp.begin(); it != tmp.end(); it++ ){
// std::cout << *it << std::endl;
//}

// *** TESTING FOR HTTP_REQUEST
// #include <fcntl.h>
// #include <unistd.h>
// int fd = open("get.example", O_RDONLY);
// if (fd < 0)
// return -1;
// try {
// HttpRequest http(fd);
// }
// catch (std::runtime_error &e) {
// std::cerr << "Error: " << e.what() << std::endl;
// }

return 0;
}
2 changes: 1 addition & 1 deletion src/Response/Response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ void Response::processResponse(HttpRequest &ReqObj){
// CGI REQUEST CHECK HANDLER
// note this is the only part of the check that returns
if(isCgiRequest(ReqObj.getUri())){ //should be ok but some errro with cgi handler cant find files
std::cout << "CGI REQUEST" << std::endl;
std::cout << "CGI REQUEST" << '\n';
int result = handleCgi(ReqObj);
//std::cout << "CGI result" << result << '\n';
if(result == 0) {
Expand Down
1 change: 0 additions & 1 deletion src/Response/delete_Response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ void Response::HandleDeleteRequest(HttpRequest& ReqObj, PathInfo& pathInfo){

// Attempt to delete the file
if (std::remove(fullPath.c_str()) == 0) {
// std::cout << "File deleted successfully: " << fullPath << std::endl;
setBody("<html><body><h1>File Deleted Successfully</h1></body></html>");
} else {
std::cerr << "Failed to delete file: " << fullPath << std::endl;
Expand Down
3 changes: 0 additions & 3 deletions src/Response/get_Response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ std::string Response::constructFullPath(const std::string uri){
if (_locationConf && uri.find(_locationConf->getPath()) == 0) {
// URI already starts with location path add uri
fullPath += uri;
//std::cout << "Path constructed from URI only: " << fullPath << std::endl;
} else if (_locationConf) {
// Location doesn't match URI prefix, need to combine them
fullPath += _locationConf->getPath() + uri;
//std::cout << "Path constructed from location + URI: " << fullPath << std::endl;
} else {
// No location matched
fullPath += uri;
Expand Down Expand Up @@ -125,7 +123,6 @@ void Response::HandleGetRequest(HttpRequest& ReqObj, PathInfo& pathInfo) {
}
}

//std::cerr << "Path is neither a file nor a directory" << std::endl;
ReqObj.setResponseCode(404);
throw 404; // Not Found
}
Expand Down
Loading