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)
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"

View File

@@ -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"

View File

@@ -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;

View File

@@ -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;