diff --git a/README.md b/README.md index 8d05333..47ed596 100644 --- a/README.md +++ b/README.md @@ -51,17 +51,17 @@ svr.listen_after_bind(); ```cpp // Mount / to ./www directory -auto ret = svr.set_mount_point("./www", "/"); +auto ret = svr.set_mount_point("/", "./www"); if (!ret) { // The specified base directory doesn't exist... } // Mount /public to ./www directory -ret = svr.set_mount_point("./www", "/public"); +ret = svr.set_mount_point("/public", "./www"); // Mount /public to ./www1 and ./www2 directories -ret = svr.set_mount_point("./www1", "/public"); // 1st order to search -ret = svr.set_mount_point("./www2", "/public"); // 2nd order to search +ret = svr.set_mount_point("/public", "./www1"); // 1st order to search +ret = svr.set_mount_point("/public", "./www2"); // 2nd order to search // Remove mount / ret = svr.remove_mount_point("/"); diff --git a/example/simplesvr.cc b/example/simplesvr.cc index 46234c7..841bc35 100644 --- a/example/simplesvr.cc +++ b/example/simplesvr.cc @@ -122,7 +122,7 @@ int main(int argc, const char **argv) { auto base_dir = "./"; if (argc > 2) { base_dir = argv[2]; } - if (!svr.set_mount_point(base_dir, "/")) { + if (!svr.set_mount_point("/", base_dir)) { cout << "The specified base directory doesn't exist..."; return 1; } diff --git a/httplib.h b/httplib.h index d5620da..2b447f7 100644 --- a/httplib.h +++ b/httplib.h @@ -466,7 +466,7 @@ public: Server &Options(const char *pattern, Handler handler); [[deprecated]] bool set_base_dir(const char *dir, const char *mount_point = nullptr); - bool set_mount_point(const char *dir, const char *mount_point); + bool set_mount_point(const char *mount_point, const char* dir); bool remove_mount_point(const char *mount_point); void set_file_extension_and_mimetype_mapping(const char *ext, const char *mime); @@ -2891,10 +2891,10 @@ inline Server &Server::Options(const char *pattern, Handler handler) { } inline bool Server::set_base_dir(const char *dir, const char *mount_point) { - return set_mount_point(dir, mount_point); + return set_mount_point(mount_point, dir); } -inline bool Server::set_mount_point(const char *dir, const char *mount_point) { +inline bool Server::set_mount_point(const char *mount_point, const char* dir) { if (detail::is_dir(dir)) { std::string mnt = mount_point ? mount_point : "/"; if (!mnt.empty() && mnt[0] == '/') { diff --git a/test/test.cc b/test/test.cc index 22daf70..c1cdec8 100644 --- a/test/test.cc +++ b/test/test.cc @@ -662,8 +662,8 @@ protected: } virtual void SetUp() { - svr_.set_mount_point("./www", "/"); - svr_.set_mount_point("./www2", "/mount"); + svr_.set_mount_point("/", "./www"); + svr_.set_mount_point("/mount", "./www2"); svr_.set_file_extension_and_mimetype_mapping("abcde", "text/abcde"); svr_.Get("/hi", @@ -1245,7 +1245,7 @@ TEST_F(ServerTest, UserDefinedMIMETypeMapping) { } TEST_F(ServerTest, InvalidBaseDirMount) { - EXPECT_EQ(false, svr_.set_mount_point("./www3", "invalid_mount_point")); + EXPECT_EQ(false, svr_.set_mount_point("invalid_mount_point", "./www3")); } TEST_F(ServerTest, EmptyRequest) { @@ -2082,7 +2082,7 @@ TEST(MountTest, Unmount) { Client cli("localhost", PORT); - svr.set_mount_point("./www2", "/mount2"); + svr.set_mount_point("/mount2", "./www2"); auto res = cli.Get("/"); ASSERT_TRUE(res != nullptr); @@ -2092,7 +2092,7 @@ TEST(MountTest, Unmount) { ASSERT_TRUE(res != nullptr); EXPECT_EQ(200, res->status); - svr.set_mount_point("./www", "/"); + svr.set_mount_point("/", "./www"); res = cli.Get("/dir/"); ASSERT_TRUE(res != nullptr);