add: $request_file

This commit is contained in:
Talyx
2022-02-20 20:00:03 +03:00
parent 4f0173ea08
commit 9fbb6cf91b
4 changed files with 33 additions and 16 deletions

View File

@@ -4,18 +4,18 @@
port = 8080 # check num, (0, 65536) port = 8080 # check num, (0, 65536)
body_size_limit = 10000000 #(pofig and > 0) body_size_limit = 10000000 #(pofig and > 0)
[server.error_page] [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]] [[server.location]]
location = "/" # mandatory location = "/" # mandatory
root = "www/" # check valid root = "www/real/" # check valid
methods = ["GET", "POST", "DELETE"] methods = ["GET", "POST", "DELETE"]
autoindex = true #check if bool autoindex = true #check if bool
directory_file = "index.html" directory_file = "index.html"
upload_accept = true #throw exception if not bool upload_accept = true #throw exception if not bool
upload_dir = "www/upload" # check valid upload_dir = "www/real/upload" # check valid
[[server.location]] [[server.location]]
location = "/images" location = "/images"
root = "www/images" root = "www/real/images"
methods = ["GET"] methods = ["GET"]
autoindex = true autoindex = true
[[server.location]] [[server.location]]
@@ -26,20 +26,20 @@
redirect = ["301", "http://127.0.0.1:8080/168.png"] redirect = ["301", "http://127.0.0.1:8080/168.png"]
[[server.location]] [[server.location]]
location = "*.jpeg" location = "*.jpeg"
root = "www/images/jpegImg" root = "www/real/images/jpegImg"
methods = ["GET", "PUT"] methods = ["GET", "PUT"]
[[server.location]] [[server.location]]
location = "*.png" location = "*.png"
root = "www/images/pngImg" root = "www/real/images/pngImg"
methods = ["GET"] methods = ["GET"]
[[server.location]] [[server.location]]
location = "/errorFolder" location = "/errorFolder"
root = "www/errorFolder" root = "www/real/errorFolder"
methods = ["GET", "POST"] methods = ["GET", "POST"]
autoindex = true autoindex = true
[[server.location]] [[server.location]]
location = "*.php" location = "*.php"
root = "www/script" root = "www/real/script"
autoindex = false autoindex = false
cgi_pass = "/usr/bin/php-cgi" #check valid cgi_pass = "/usr/bin/php-cgi" #check valid
[[server]] [[server]]
@@ -59,7 +59,7 @@
autoindex = true autoindex = true
directory_file = "index.html" directory_file = "index.html"
upload_accept = false upload_accept = false
upload_dir = "www/upload" upload_dir = "www/real/upload"
[[server]] [[server]]
name = "localhost" name = "localhost"
host = "127.0.0.1" host = "127.0.0.1"
@@ -77,4 +77,4 @@
autoindex = true autoindex = true
directory_file = "index.html" directory_file = "index.html"
upload_accept = false upload_accept = false
upload_dir = "www/upload" upload_dir = "www/real/upload"

View File

@@ -5,26 +5,27 @@
body_size_limit = 100000000 body_size_limit = 100000000
[[server.location]] [[server.location]]
location = "/" location = "/"
root = "tester/" root = "www/tester/"
methods = ["GET"] methods = ["GET"]
autoindex = true autoindex = true
directory_file = "index.html" directory_file = "index.html"
[[server.location]] [[server.location]]
location = "/put_test" location = "/put_test"
root = "tester/" root = "www/tester/"
methods = ["PUT"] methods = ["PUT"]
autoindex = true autoindex = true
upload_dir = "tester/upload_here/" upload_accept = true
upload_dir = "www/tester/upload_here/"
[[server.location]] [[server.location]]
location = "*.bla" location = "*.bla"
cgi_pass = "ubuntu_cgi_tester" cgi_pass = "ubuntu_cgi_tester"
[[server.location]] [[server.location]]
location = "/post_body" location = "/post_body"
root = "tester/" root = "www/tester/"
methods = ["POST"] methods = ["POST"]
body_size_limit = 100 body_size_limit = 100
[[server.location]] [[server.location]]
location = "/directory" location = "/directory"
methods = ["GET"] methods = ["GET"]
root = "tester/YoupiBanane/" root = "www/tester/YoupiBanane/"
directory_file = "youpi.bad_extension" directory_file = "youpi.bad_extension"

View File

@@ -118,7 +118,16 @@ void Response::setCacheControl(void)
void Response::setLocation(void) void Response::setLocation(void)
{ {
if (_code == 301) 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() serverListen Response::getListen()
@@ -237,6 +246,7 @@ std::string Response::getFullURI(void)
int pos = 0; int pos = 0;
pos = _request.getURI().rfind("/"); pos = _request.getURI().rfind("/");
tmp = _request.getURI().substr(pos); tmp = _request.getURI().substr(pos);
_request_file = tmp;
if (!_location->uploadDir.empty()) if (!_location->uploadDir.empty())
_upload_dir = _location->uploadDir + tmp; _upload_dir = _location->uploadDir + tmp;
tmp = _location->root + tmp; tmp = _location->root + tmp;
@@ -244,6 +254,7 @@ std::string Response::getFullURI(void)
else else
{ {
tmp = _request.getURI().substr(len); tmp = _request.getURI().substr(len);
_request_file = tmp;
if (!_location->uploadDir.empty()) if (!_location->uploadDir.empty())
_upload_dir = _location->uploadDir + tmp; _upload_dir = _location->uploadDir + tmp;
tmp = _location->root + tmp; tmp = _location->root + tmp;
@@ -380,6 +391,8 @@ void Response::generate2(serverListen &l)
bool Response::isRedirect() bool Response::isRedirect()
{ {
if (_location == NULL)
return (false);
if (!_location->redirect.empty()) if (!_location->redirect.empty())
{ {
_code = 301; _code = 301;

View File

@@ -22,6 +22,9 @@ private:
serverListen _hostPort; serverListen _hostPort;
std::string _method; std::string _method;
std::string _request_file;
std::string _redirect_location;
private: private:
std::string _contentType; std::string _contentType;
ssize_t _contentLength; ssize_t _contentLength;