Skip to content

Commit

Permalink
Folder index file fix
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwqr-000 committed May 7, 2024
1 parent 9e83f00 commit 4fc2561
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions whiteavocado-web-server/classes/Website.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,14 @@ class Website : Server {
return res;
}

std::string getFilenameExtention(const std::string &path) {//Get the extention name from a path if it has one
std::string getFilenameExtention(std::string path) {//Get the extention name from a path if it has one
if (path.back() == '/') {
std::string Fol = "folder";
std::reverse(Fol.begin(), Fol.end());
return Fol;
if (path == "/") {
path = this->indexFile;
}
else {
path += this->indexFile;
}
}
bool isValid = false;
std::string ext = "";
Expand Down Expand Up @@ -330,9 +333,16 @@ class Website : Server {
std::string bufStr(&buffer);
std::string normalResp = "";
std::string requestPath = getClientPath(bufStr);
bool whiteListed = isWhitelisted(requestPath);
if (getFilenameExtention(requestPath) == "enon") {
requestPath += "/";
requestPath += this->indexFile;
}
if (!whiteListed) {//If index file inside folder is fully typed out, check the whitelist
whiteListed = isWhitelisted(requestPath);
}
std::string extention = getFilenameExtention(requestPath);
std::string cct = getContentType(extention);
bool whiteListed = isWhitelisted(requestPath);

if (requestPath == "/" || whiteListed) {
std::cout << getCurrentDateTime() << " => " << requestPath << " -> " + this->clientIP + "\n";
Expand Down Expand Up @@ -419,4 +429,4 @@ class Website : Server {
void startup() {
start();
}
};
};

0 comments on commit 4fc2561

Please sign in to comment.