diff --git a/http_examples.cpp b/http_examples.cpp index dbea3a6..f8533b1 100644 --- a/http_examples.cpp +++ b/http_examples.cpp @@ -106,7 +106,7 @@ int main() { //Can for instance be used to retrieve an HTML 5 client that uses REST-resources on this server server.default_resource["GET"]=[&server](shared_ptr response, shared_ptr request) { try { - auto web_root_path=boost::filesystem::canonical("web"); + static auto web_root_path=boost::filesystem::canonical("web"); auto path=boost::filesystem::canonical(web_root_path/request->path); //Check if path is within web_root_path if(distance(web_root_path.begin(), web_root_path.end())>distance(path.begin(), path.end()) || @@ -114,8 +114,6 @@ int main() { throw invalid_argument("path must be within root path"); if(boost::filesystem::is_directory(path)) path/="index.html"; - if(!(boost::filesystem::exists(path) && boost::filesystem::is_regular_file(path))) - throw invalid_argument("file does not exist"); auto ifs=make_shared(); ifs->open(path.string(), ifstream::in | ios::binary); diff --git a/https_examples.cpp b/https_examples.cpp index 8642a42..a932d56 100644 --- a/https_examples.cpp +++ b/https_examples.cpp @@ -106,7 +106,7 @@ int main() { //Can for instance be used to retrieve an HTML 5 client that uses REST-resources on this server server.default_resource["GET"]=[&server](shared_ptr response, shared_ptr request) { try { - auto web_root_path=boost::filesystem::canonical("web"); + static auto web_root_path=boost::filesystem::canonical("web"); auto path=boost::filesystem::canonical(web_root_path/request->path); //Check if path is within web_root_path if(distance(web_root_path.begin(), web_root_path.end())>distance(path.begin(), path.end()) || @@ -114,8 +114,6 @@ int main() { throw invalid_argument("path must be within root path"); if(boost::filesystem::is_directory(path)) path/="index.html"; - if(!(boost::filesystem::exists(path) && boost::filesystem::is_regular_file(path))) - throw invalid_argument("file does not exist"); auto ifs=make_shared(); ifs->open(path.string(), ifstream::in | ios::binary);