Minor cleanup of default_resource example

This commit is contained in:
eidheim 2016-10-19 09:41:58 +02:00
commit e50f0b597f
2 changed files with 2 additions and 6 deletions

View file

@ -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<HttpsServer::Response> response, shared_ptr<HttpsServer::Request> 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<ifstream>();
ifs->open(path.string(), ifstream::in | ios::binary);