diff --git a/config/real.toml b/config/real.toml index 297a318..c9a5c5e 100644 --- a/config/real.toml +++ b/config/real.toml @@ -4,18 +4,18 @@ port = 8080 # check num, (0, 65536) body_size_limit = 10000000 #(pofig and > 0) [server.error_page] - "404" = "www/errorFolder/error_404.html" # throw exception if not string + "404" = "www/real/errorFolder/error_404.html" # throw exception if not string [[server.location]] location = "/" # mandatory - root = "www/" # check valid + root = "www/real/" # check valid methods = ["GET", "POST", "DELETE"] autoindex = true #check if bool directory_file = "index.html" upload_accept = true #throw exception if not bool - upload_dir = "www/upload" # check valid + upload_dir = "www/real/upload" # check valid [[server.location]] location = "/images" - root = "www/images" + root = "www/real/images" methods = ["GET"] autoindex = true [[server.location]] @@ -26,20 +26,20 @@ redirect = ["301", "http://127.0.0.1:8080/168.png"] [[server.location]] location = "*.jpeg" - root = "www/images/jpegImg" + root = "www/real/images/jpegImg" methods = ["GET", "PUT"] [[server.location]] location = "*.png" - root = "www/images/pngImg" + root = "www/real/images/pngImg" methods = ["GET"] [[server.location]] location = "/errorFolder" - root = "www/errorFolder" + root = "www/real/errorFolder" methods = ["GET", "POST"] autoindex = true [[server.location]] location = "*.php" - root = "www/script" + root = "www/real/script" autoindex = false cgi_pass = "/usr/bin/php-cgi" #check valid [[server]] @@ -59,7 +59,7 @@ autoindex = true directory_file = "index.html" upload_accept = false - upload_dir = "www/upload" + upload_dir = "www/real/upload" [[server]] name = "localhost" host = "127.0.0.1" @@ -77,4 +77,4 @@ autoindex = true directory_file = "index.html" upload_accept = false - upload_dir = "www/upload" + upload_dir = "www/real/upload" diff --git a/config/tester.toml b/config/tester.toml index 389d49a..c52cbd7 100644 --- a/config/tester.toml +++ b/config/tester.toml @@ -5,26 +5,27 @@ body_size_limit = 100000000 [[server.location]] location = "/" - root = "tester/" + root = "www/tester/" methods = ["GET"] autoindex = true directory_file = "index.html" [[server.location]] location = "/put_test" - root = "tester/" + root = "www/tester/" methods = ["PUT"] autoindex = true - upload_dir = "tester/upload_here/" + upload_accept = true + upload_dir = "www/tester/upload_here/" [[server.location]] location = "*.bla" cgi_pass = "ubuntu_cgi_tester" [[server.location]] location = "/post_body" - root = "tester/" + root = "www/tester/" methods = ["POST"] body_size_limit = 100 [[server.location]] location = "/directory" methods = ["GET"] - root = "tester/YoupiBanane/" + root = "www/tester/YoupiBanane/" directory_file = "youpi.bad_extension" diff --git a/src/Client/Response.cpp b/src/Client/Response.cpp index 8dac10e..8a37901 100644 --- a/src/Client/Response.cpp +++ b/src/Client/Response.cpp @@ -118,7 +118,16 @@ void Response::setCacheControl(void) void Response::setLocation(void) { if (_code == 301) - _locationSTR = _location->redirect[_code]; + { + _redirect_location = _location->redirect[_code]; + unsigned long pos = _redirect_location.rfind("$request_file"); + if (pos != std::string::npos) + { + _redirect_location.erase(pos); + _redirect_location += _request_file; + } + _locationSTR = _redirect_location; + } } serverListen Response::getListen() @@ -237,6 +246,7 @@ std::string Response::getFullURI(void) int pos = 0; pos = _request.getURI().rfind("/"); tmp = _request.getURI().substr(pos); + _request_file = tmp; if (!_location->uploadDir.empty()) _upload_dir = _location->uploadDir + tmp; tmp = _location->root + tmp; @@ -244,6 +254,7 @@ std::string Response::getFullURI(void) else { tmp = _request.getURI().substr(len); + _request_file = tmp; if (!_location->uploadDir.empty()) _upload_dir = _location->uploadDir + tmp; tmp = _location->root + tmp; @@ -380,6 +391,8 @@ void Response::generate2(serverListen &l) bool Response::isRedirect() { + if (_location == NULL) + return (false); if (!_location->redirect.empty()) { _code = 301; diff --git a/src/Client/Response.hpp b/src/Client/Response.hpp index 0262731..d33fc67 100644 --- a/src/Client/Response.hpp +++ b/src/Client/Response.hpp @@ -22,6 +22,9 @@ private: serverListen _hostPort; std::string _method; + std::string _request_file; + std::string _redirect_location; + private: std::string _contentType; ssize_t _contentLength;