mirror of
https://github.com/yhirose/cpp-httplib
synced 2024-11-21 14:29:10 -07:00
Changed the order of parameters of set_mounting_point.
This commit is contained in:
parent
82c11168c1
commit
ac7742bb32
4 changed files with 13 additions and 13 deletions
|
@ -51,17 +51,17 @@ svr.listen_after_bind();
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
// Mount / to ./www directory
|
// Mount / to ./www directory
|
||||||
auto ret = svr.set_mount_point("./www", "/");
|
auto ret = svr.set_mount_point("/", "./www");
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
// The specified base directory doesn't exist...
|
// The specified base directory doesn't exist...
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mount /public to ./www directory
|
// 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
|
// Mount /public to ./www1 and ./www2 directories
|
||||||
ret = svr.set_mount_point("./www1", "/public"); // 1st order to search
|
ret = svr.set_mount_point("/public", "./www1"); // 1st order to search
|
||||||
ret = svr.set_mount_point("./www2", "/public"); // 2nd order to search
|
ret = svr.set_mount_point("/public", "./www2"); // 2nd order to search
|
||||||
|
|
||||||
// Remove mount /
|
// Remove mount /
|
||||||
ret = svr.remove_mount_point("/");
|
ret = svr.remove_mount_point("/");
|
||||||
|
|
|
@ -122,7 +122,7 @@ int main(int argc, const char **argv) {
|
||||||
auto base_dir = "./";
|
auto base_dir = "./";
|
||||||
if (argc > 2) { base_dir = argv[2]; }
|
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...";
|
cout << "The specified base directory doesn't exist...";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -466,7 +466,7 @@ public:
|
||||||
Server &Options(const char *pattern, Handler handler);
|
Server &Options(const char *pattern, Handler handler);
|
||||||
|
|
||||||
[[deprecated]] bool set_base_dir(const char *dir, const char *mount_point = nullptr);
|
[[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);
|
bool remove_mount_point(const char *mount_point);
|
||||||
void set_file_extension_and_mimetype_mapping(const char *ext,
|
void set_file_extension_and_mimetype_mapping(const char *ext,
|
||||||
const char *mime);
|
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) {
|
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)) {
|
if (detail::is_dir(dir)) {
|
||||||
std::string mnt = mount_point ? mount_point : "/";
|
std::string mnt = mount_point ? mount_point : "/";
|
||||||
if (!mnt.empty() && mnt[0] == '/') {
|
if (!mnt.empty() && mnt[0] == '/') {
|
||||||
|
|
10
test/test.cc
10
test/test.cc
|
@ -662,8 +662,8 @@ protected:
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void SetUp() {
|
virtual void SetUp() {
|
||||||
svr_.set_mount_point("./www", "/");
|
svr_.set_mount_point("/", "./www");
|
||||||
svr_.set_mount_point("./www2", "/mount");
|
svr_.set_mount_point("/mount", "./www2");
|
||||||
svr_.set_file_extension_and_mimetype_mapping("abcde", "text/abcde");
|
svr_.set_file_extension_and_mimetype_mapping("abcde", "text/abcde");
|
||||||
|
|
||||||
svr_.Get("/hi",
|
svr_.Get("/hi",
|
||||||
|
@ -1245,7 +1245,7 @@ TEST_F(ServerTest, UserDefinedMIMETypeMapping) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ServerTest, InvalidBaseDirMount) {
|
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) {
|
TEST_F(ServerTest, EmptyRequest) {
|
||||||
|
@ -2082,7 +2082,7 @@ TEST(MountTest, Unmount) {
|
||||||
|
|
||||||
Client cli("localhost", PORT);
|
Client cli("localhost", PORT);
|
||||||
|
|
||||||
svr.set_mount_point("./www2", "/mount2");
|
svr.set_mount_point("/mount2", "./www2");
|
||||||
|
|
||||||
auto res = cli.Get("/");
|
auto res = cli.Get("/");
|
||||||
ASSERT_TRUE(res != nullptr);
|
ASSERT_TRUE(res != nullptr);
|
||||||
|
@ -2092,7 +2092,7 @@ TEST(MountTest, Unmount) {
|
||||||
ASSERT_TRUE(res != nullptr);
|
ASSERT_TRUE(res != nullptr);
|
||||||
EXPECT_EQ(200, res->status);
|
EXPECT_EQ(200, res->status);
|
||||||
|
|
||||||
svr.set_mount_point("./www", "/");
|
svr.set_mount_point("/", "./www");
|
||||||
|
|
||||||
res = cli.Get("/dir/");
|
res = cli.Get("/dir/");
|
||||||
ASSERT_TRUE(res != nullptr);
|
ASSERT_TRUE(res != nullptr);
|
||||||
|
|
Loading…
Reference in a new issue