&&callback,
6 | const std::string &userName) const
7 | {
8 | auto resp = HttpResponse::newHttpResponse();
9 | resp->setBody("" + greetings_ + ", " + userName + "
");
10 | callback(resp);
11 | }
12 |
--------------------------------------------------------------------------------
/cmake/templates/config.h.in:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #cmakedefine01 USE_POSTGRESQL
4 | #cmakedefine01 LIBPQ_SUPPORTS_BATCH_MODE
5 | #cmakedefine01 USE_MYSQL
6 | #cmakedefine01 USE_SQLITE3
7 | #cmakedefine OpenSSL_FOUND
8 | #cmakedefine Boost_FOUND
9 |
10 | #cmakedefine COMPILATION_FLAGS "@COMPILATION_FLAGS@@DROGON_CXX_STANDARD@"
11 | #cmakedefine COMPILER_COMMAND "@COMPILER_COMMAND@"
12 | #cmakedefine COMPILER_ID "@COMPILER_ID@"
13 |
14 | #cmakedefine INCLUDING_DIRS "@INCLUDING_DIRS@"
15 |
--------------------------------------------------------------------------------
/examples/simple_example/ForwardCtrl.cc:
--------------------------------------------------------------------------------
1 | #include "ForwardCtrl.h"
2 | void ForwardCtrl::asyncHandleHttpRequest(
3 | const HttpRequestPtr &req,
4 | std::function &&callback)
5 | {
6 | req->setPath("/repos/an-tao/drogon/git/refs/heads/master");
7 | app().forward(
8 | req,
9 | [callback = std::move(callback)](const HttpResponsePtr &resp) {
10 | callback(resp);
11 | },
12 | "https://api.github.com");
13 | }
--------------------------------------------------------------------------------
/examples/benchmark/JsonCtrl.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | using namespace drogon;
4 | class JsonCtrl : public drogon::HttpSimpleController
5 | {
6 | public:
7 | virtual void asyncHandleHttpRequest(
8 | const HttpRequestPtr &req,
9 | std::function &&callback) override;
10 | PATH_LIST_BEGIN
11 | // list path definitions here;
12 | PATH_ADD("/json", Get);
13 | PATH_LIST_END
14 | };
15 |
--------------------------------------------------------------------------------
/drogon_ctl/templates/gitignore.csp:
--------------------------------------------------------------------------------
1 | # Prerequisites
2 | *.d
3 |
4 | # Compiled Object files
5 | *.slo
6 | *.lo
7 | *.o
8 | *.obj
9 |
10 | # Precompiled Headers
11 | *.gch
12 | *.pch
13 |
14 | # Compiled Dynamic libraries
15 | *.so
16 | *.dylib
17 | *.dll
18 |
19 | # Fortran module files
20 | *.mod
21 | *.smod
22 |
23 | # Compiled Static libraries
24 | *.lai
25 | *.la
26 | *.a
27 | *.lib
28 |
29 | # Executables
30 | *.exe
31 | *.out
32 | *.app
33 |
34 | build
35 | cmake-build-debug
36 | .idea
37 |
--------------------------------------------------------------------------------
/examples/simple_reverse_proxy/.gitignore:
--------------------------------------------------------------------------------
1 | # Prerequisites
2 | *.d
3 |
4 | # Compiled Object files
5 | *.slo
6 | *.lo
7 | *.o
8 | *.obj
9 |
10 | # Precompiled Headers
11 | *.gch
12 | *.pch
13 |
14 | # Compiled Dynamic libraries
15 | *.so
16 | *.dylib
17 | *.dll
18 |
19 | # Fortran module files
20 | *.mod
21 | *.smod
22 |
23 | # Compiled Static libraries
24 | *.lai
25 | *.la
26 | *.a
27 | *.lib
28 |
29 | # Executables
30 | *.exe
31 | *.out
32 | *.app
33 |
34 | build
35 | cmake-build-debug
36 | .idea
37 |
--------------------------------------------------------------------------------
/examples/simple_example/ForwardCtrl.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | using namespace drogon;
4 | class ForwardCtrl : public drogon::HttpSimpleController
5 | {
6 | public:
7 | virtual void asyncHandleHttpRequest(
8 | const HttpRequestPtr &req,
9 | std::function &&callback) override;
10 | PATH_LIST_BEGIN
11 | // list path definitions here;
12 | PATH_ADD("/forward", Get);
13 | PATH_LIST_END
14 | };
15 |
--------------------------------------------------------------------------------
/examples/simple_example/PipeliningTest.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | using namespace drogon;
4 | class PipeliningTest : public drogon::HttpSimpleController
5 | {
6 | public:
7 | virtual void asyncHandleHttpRequest(
8 | const HttpRequestPtr &req,
9 | std::function &&callback) override;
10 | PATH_LIST_BEGIN
11 | // list path definitions here;
12 | PATH_ADD("/pipe", Get);
13 | PATH_LIST_END
14 | };
15 |
--------------------------------------------------------------------------------
/lib/tests/CookiesTest.cc:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | int main()
4 | {
5 | drogon::Cookie cookie1("test", "1");
6 | std::cout << cookie1.cookieString();
7 | drogon::Cookie cookie2("test", "2");
8 | cookie2.setSecure(true);
9 | std::cout << cookie2.cookieString();
10 | drogon::Cookie cookie3("test", "3");
11 | cookie3.setDomain("drogon.org");
12 | cookie3.setExpiresDate(trantor::Date::date().after(3600 * 24));
13 | std::cout << cookie3.cookieString();
14 | }
15 |
--------------------------------------------------------------------------------
/drogon_ctl/templates/plugin_cc.csp:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * [[filename]].cc
4 | *
5 | */
6 |
7 | #include "[[filename]].h"
8 |
9 | using namespace drogon;
10 | <%c++auto namespaceStr=@@.get("namespaceString");
11 | if(!namespaceStr.empty())
12 | $$<<"using namespace "<
14 |
15 | void [[className]]::initAndStart(const Json::Value &config)
16 | {
17 | /// Initialize and start the plugin
18 | }
19 |
20 | void [[className]]::shutdown()
21 | {
22 | /// Shutdown the plugin
23 | }
24 |
--------------------------------------------------------------------------------
/examples/simple_example/ListParaCtl.cc:
--------------------------------------------------------------------------------
1 | #include "ListParaCtl.h"
2 | void ListParaCtl::asyncHandleHttpRequest(
3 | const HttpRequestPtr &req,
4 | std::function &&callback)
5 | {
6 | // write your application logic here
7 | HttpViewData data;
8 | data.insert("title", "list parameters");
9 | data.insert("parameters", req->getParameters());
10 | auto res =
11 | drogon::HttpResponse::newHttpViewResponse("ListParaView.csp", data);
12 | callback(res);
13 | }
14 |
--------------------------------------------------------------------------------
/drogon_ctl/cmd.h:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * cmd.h
4 | * An Tao
5 | *
6 | * Copyright 2018, An Tao. All rights reserved.
7 | * https://github.com/an-tao/drogon
8 | * Use of this source code is governed by a MIT license
9 | * that can be found in the License file.
10 | *
11 | * Drogon
12 | *
13 | */
14 |
15 | #pragma once
16 |
17 | #include
18 | #include
19 | #include
20 | #define ARGS_ERROR_STR "args error!use help command to get usage!"
21 | void exeCommand(std::vector ¶meters);
22 |
--------------------------------------------------------------------------------
/examples/simple_example/TimeFilter.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by antao on 2018/5/22.
3 | //
4 |
5 | #pragma once
6 |
7 | #include
8 | using namespace drogon;
9 |
10 | class TimeFilter : public drogon::HttpFilter
11 | {
12 | public:
13 | virtual void doFilter(const HttpRequestPtr &req,
14 | FilterCallback &&cb,
15 | FilterChainCallback &&ccb) override;
16 | TimeFilter()
17 | {
18 | LOG_DEBUG << "TimeFilter constructor";
19 | }
20 | };
21 |
--------------------------------------------------------------------------------
/lib/src/ssl_funcs/Sha1.h:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Sha1.h
4 | * An Tao
5 | *
6 | * Copyright 2018, An Tao. All rights reserved.
7 | * https://github.com/an-tao/drogon
8 | * Use of this source code is governed by a MIT license
9 | * that can be found in the License file.
10 | *
11 | * Drogon
12 | *
13 | */
14 |
15 | #pragma once
16 |
17 | #include
18 |
19 | #define SHA_DIGEST_LENGTH 20
20 |
21 | unsigned char *SHA1(const unsigned char *dataIn,
22 | size_t dataLen,
23 | unsigned char *dataOut);
24 |
--------------------------------------------------------------------------------
/examples/simple_example/ListParaCtl.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | using namespace drogon;
4 | class ListParaCtl : public drogon::HttpSimpleController
5 | {
6 | public:
7 | virtual void asyncHandleHttpRequest(
8 | const HttpRequestPtr &req,
9 | std::function &&callback) override;
10 | PATH_LIST_BEGIN
11 | // list path definations here;
12 | // PATH_ADD("/path","filter1","filter2",...);
13 | PATH_ADD("/listpara", Get);
14 | PATH_LIST_END
15 | };
16 |
--------------------------------------------------------------------------------
/examples/simple_example/JsonTestController.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | using namespace drogon;
5 |
6 | class JsonTestController
7 | : public drogon::HttpSimpleController
8 | {
9 | public:
10 | // TestController(){}
11 | virtual void asyncHandleHttpRequest(
12 | const HttpRequestPtr &req,
13 | std::function &&callback) override;
14 |
15 | PATH_LIST_BEGIN
16 | PATH_ADD("/json", Get, "drogon::LocalHostFilter");
17 | PATH_LIST_END
18 | };
19 |
--------------------------------------------------------------------------------
/lib/tests/MainLoopTest2.cc:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | /**
6 | * @brief This test program tests to call the app().run() in another thread.
7 | *
8 | */
9 | int main()
10 | {
11 | std::thread([]() {
12 | drogon::app().getLoop()->runEvery(1, []() {
13 | std::cout << "!" << std::endl;
14 | });
15 | }).detach();
16 |
17 | std::thread l([]() { drogon::app().run(); });
18 | std::this_thread::sleep_for(std::chrono::seconds(1));
19 | trantor::EventLoop loop;
20 | l.join();
21 | }
--------------------------------------------------------------------------------
/examples/simple_example/TestViewCtl.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | using namespace drogon;
4 | class TestViewCtl : public drogon::HttpSimpleController
5 | {
6 | public:
7 | virtual void asyncHandleHttpRequest(
8 | const HttpRequestPtr &req,
9 | std::function &&callback) override;
10 | PATH_LIST_BEGIN
11 | // list path definations here;
12 | // PATH_ADD("/path","filter1","filter2",...);
13 | PATH_ADD("/view");
14 | PATH_ADD("/", Post);
15 | PATH_LIST_END
16 | };
17 |
--------------------------------------------------------------------------------
/lib/tests/HttpViewDataTest.cc:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | int main()
4 | {
5 | drogon::HttpViewData data;
6 | std::cout << (data.insert("1", 1), data.get("1")) << std::endl;
7 | std::cout << (data.insertAsString("2", 2.0), data.get("2"))
8 | << std::endl;
9 | std::cout << (data.insertFormattedString("3", "third value is %d", 3),
10 | data.get("3"))
11 | << std::endl;
12 | std::cout << (data.insertAsString("4", "4"), data.get("4"))
13 | << std::endl;
14 | }
15 |
--------------------------------------------------------------------------------
/lib/tests/ClassNameTest.cc:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | namespace api
4 | {
5 | namespace v1
6 | {
7 | template
8 | class handler : public drogon::DrObject
9 | {
10 | public:
11 | static void p()
12 | {
13 | std::cout << handler::classTypeName() << std::endl;
14 | }
15 | };
16 | class hh : public handler
17 | {
18 | };
19 | } // namespace v1
20 | } // namespace api
21 | int main()
22 | {
23 | api::v1::hh h;
24 | std::cout << h.className() << std::endl;
25 | std::cout << api::v1::hh::classTypeName() << std::endl;
26 | h.p();
27 | }
28 |
--------------------------------------------------------------------------------
/lib/tests/UrlCodecTest.cc:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | int main()
6 | {
7 | std::string input = "k1=1&k2=安";
8 | auto output = drogon::utils::urlEncode(input);
9 | std::cout << output << std::endl;
10 | auto output2 = drogon::utils::urlDecode(output);
11 | std::cout << output2 << std::endl;
12 | std::cout << drogon::utils::urlEncode("k2=安&k1=1") << std::endl;
13 | std::cout << drogon::utils::urlDecode(
14 | drogon::string_view("k2%3D%E5%AE%89&k1%3D1"))
15 | << std::endl;
16 | return 0;
17 | }
--------------------------------------------------------------------------------
/unittest/MD5Unittest.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | TEST(Md5Test, md5)
6 | {
7 | EXPECT_EQ(drogon::utils::getMd5(
8 | "123456789012345678901234567890123456789012345"
9 | "678901234567890123456789012345678901234567890"
10 | "1234567890"),
11 | "49CB3608E2B33FAD6B65DF8CB8F49668");
12 | EXPECT_EQ(drogon::utils::getMd5("1"), "C4CA4238A0B923820DCC509A6F75849B");
13 | }
14 |
15 | int main(int argc, char **argv)
16 | {
17 | testing::InitGoogleTest(&argc, argv);
18 | return RUN_ALL_TESTS();
19 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Prerequisites
2 | *.d
3 |
4 | # Compiled Object files
5 | *.slo
6 | *.lo
7 | *.o
8 | *.obj
9 |
10 | # Precompiled Headers
11 | *.gch
12 | *.pch
13 |
14 | # Compiled Dynamic libraries
15 | *.so
16 | *.dylib
17 | *.dll
18 |
19 | # Fortran module files
20 | *.mod
21 | *.smod
22 |
23 | # Compiled Static libraries
24 | *.lai
25 | *.la
26 | *.a
27 | *.lib
28 |
29 | # Executables
30 | *.exe
31 | *.out
32 | *.app
33 |
34 | build
35 | cmake-build-debug
36 | .idea
37 | lib/inc/drogon/version.h
38 | html/
39 | latex/
40 | .vscode
41 | *.kdev4
42 | .cproject
43 | .project
44 | .settings/
45 | .vs/
46 | CMakeSettings.json
47 | install
48 |
--------------------------------------------------------------------------------
/lib/inc/drogon/DrTemplate.h:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * DrTemplate.h
4 | * An Tao
5 | *
6 | * Copyright 2018, An Tao. All rights reserved.
7 | * https://github.com/an-tao/drogon
8 | * Use of this source code is governed by a MIT license
9 | * that can be found in the License file.
10 | *
11 | * Drogon
12 | *
13 | */
14 |
15 | #pragma once
16 |
17 | #include
18 | #include
19 | namespace drogon
20 | {
21 | template
22 | class DrTemplate : public DrObject, public DrTemplateBase
23 | {
24 | protected:
25 | DrTemplate()
26 | {
27 | }
28 | };
29 |
30 | } // namespace drogon
31 |
--------------------------------------------------------------------------------
/examples/simple_example/CustomHeaderFilter.cc:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * CustomHeaderFilter.cc
4 | *
5 | */
6 |
7 | #include "CustomHeaderFilter.h"
8 |
9 | using namespace drogon;
10 |
11 | void CustomHeaderFilter::doFilter(const HttpRequestPtr &req,
12 | FilterCallback &&fcb,
13 | FilterChainCallback &&fccb)
14 | {
15 | if (req->getHeader(field_) == value_)
16 | {
17 | // Passed
18 | fccb();
19 | return;
20 | }
21 | // Check failed
22 | auto res = drogon::HttpResponse::newHttpResponse();
23 | res->setStatusCode(k500InternalServerError);
24 | fcb(res);
25 | }
26 |
--------------------------------------------------------------------------------
/examples/simple_example_test/ws_test.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
24 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 | labels:
5 |
6 | ---
7 |
8 | **Is your feature request related to a problem? Please describe.**
9 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
10 |
11 | **Describe the solution you'd like**
12 | A clear and concise description of what you want to happen.
13 |
14 | **Describe alternatives you've considered**
15 | A clear and concise description of any alternative solutions or features you've considered.
16 |
17 | **Additional context**
18 | Add any other context or screenshots about the feature request here.
19 |
--------------------------------------------------------------------------------
/examples/simple_example/CustomHeaderFilter.h:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * CustomHeaderFilter.h
4 | *
5 | */
6 |
7 | #pragma once
8 |
9 | #include
10 | using namespace drogon;
11 |
12 | class CustomHeaderFilter : public HttpFilter
13 | {
14 | public:
15 | CustomHeaderFilter(const std::string &field, const std::string &value)
16 | : field_(field), value_(value)
17 | {
18 | }
19 | virtual void doFilter(const HttpRequestPtr &req,
20 | FilterCallback &&fcb,
21 | FilterChainCallback &&fccb) override;
22 |
23 | private:
24 | std::string field_;
25 | std::string value_;
26 | };
27 |
--------------------------------------------------------------------------------
/examples/simple_example/DoNothingPlugin.h:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * DoNothingPlugin.h
4 | *
5 | */
6 |
7 | #pragma once
8 |
9 | #include
10 | using namespace drogon;
11 |
12 | class DoNothingPlugin : public Plugin
13 | {
14 | public:
15 | DoNothingPlugin()
16 | {
17 | }
18 | /// This method must be called by drogon to initialize and start the plugin.
19 | /// It must be implemented by the user.
20 | virtual void initAndStart(const Json::Value &config) override;
21 |
22 | /// This method must be called by drogon to shutdown the plugin.
23 | /// It must be implemented by the user.
24 | virtual void shutdown() override;
25 | };
26 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4 | patreon: # Replace with a single Patreon username
5 | open_collective: # Replace with a single Open Collective username
6 | ko_fi: # Replace with a single Ko-fi username
7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | liberapay: # Replace with a single Liberapay username
10 | issuehunt: # Replace with a single IssueHunt username
11 | otechie: # Replace with a single Otechie username
12 | custom: ['https://paypal.me/antao2019']
13 |
--------------------------------------------------------------------------------
/lib/inc/drogon/utils/any.h:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * any.h
4 | * An Tao
5 | *
6 | * Copyright 2018, An Tao. All rights reserved.
7 | * https://github.com/an-tao/drogon
8 | * Use of this source code is governed by a MIT license
9 | * that can be found in the License file.
10 | *
11 | * Drogon
12 | *
13 | */
14 |
15 | #pragma once
16 | #if __cplusplus >= 201703L || (defined _MSC_VER && _MSC_VER > 1900)
17 | #include
18 | #else
19 | #include
20 | #endif
21 |
22 | namespace drogon
23 | {
24 | #if __cplusplus >= 201703L || (defined _MSC_VER && _MSC_VER > 1900)
25 | using std::any;
26 | using std::any_cast;
27 | #else
28 | using boost::any;
29 | using boost::any_cast;
30 | #endif
31 | } // namespace drogon
32 |
--------------------------------------------------------------------------------
/examples/benchmark/main.cc:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace drogon;
4 | int main()
5 | {
6 | app()
7 | .setLogPath("./")
8 | .setLogLevel(trantor::Logger::kWarn)
9 | .addListener("0.0.0.0", 7770)
10 | .setThreadNum(0)
11 | .registerSyncAdvice([](const HttpRequestPtr &req) -> HttpResponsePtr {
12 | const auto &path = req->path();
13 | if (path.length() == 1 && path[0] == '/')
14 | {
15 | auto response = HttpResponse::newHttpResponse();
16 | response->setBody("Hello, world!
");
17 | return response;
18 | }
19 | return nullptr;
20 | })
21 | .run();
22 | }
23 |
--------------------------------------------------------------------------------
/examples/simple_example/TestController.cc:
--------------------------------------------------------------------------------
1 | #include "TestController.h"
2 | using namespace example;
3 | void TestController::asyncHandleHttpRequest(
4 | const HttpRequestPtr &req,
5 | std::function &&callback)
6 | {
7 | // write your application logic here
8 | LOG_WARN << req->matchedPathPatternData();
9 | LOG_DEBUG << "index=" << threadIndex_.getThreadData();
10 | ++(threadIndex_.getThreadData());
11 | auto resp = HttpResponse::newHttpResponse();
12 | resp->setContentTypeCodeAndCustomString(CT_TEXT_PLAIN,
13 | "Content-Type: plaintext\r\n");
14 | resp->setBody("Hello, world!
");
15 | resp->setExpiredTime(20);
16 | callback(resp);
17 | }
18 |
--------------------------------------------------------------------------------
/examples/simple_example/ListParaView.csp:
--------------------------------------------------------------------------------
1 |
2 |
3 | <%c++
4 | auto para=@@.get>("parameters");
5 | %>
6 |
7 |
8 | [[ title ]]
9 |
10 |
11 | <%view header %>
12 | <%c++ if(para.size()>0){%>
13 | Parameters
14 |
15 |
16 | | name |
17 | value |
18 |
19 | <%c++ for(auto iter:para){%>
20 |
21 | | {%iter.first%} |
22 | <%c++ $$< |
23 |
24 | <%c++}%>
25 |
26 | <%c++ }else{%>
27 | no parameter
28 | <%c++}%>
29 |
30 |
31 |
--------------------------------------------------------------------------------
/examples/simple_example/JsonTestController.cc:
--------------------------------------------------------------------------------
1 | #include "JsonTestController.h"
2 | #include
3 | void JsonTestController::asyncHandleHttpRequest(
4 | const HttpRequestPtr &req,
5 | std::function &&callback)
6 | {
7 | Json::Value json;
8 | json["path"] = "json";
9 | json["name"] = "json test";
10 | Json::Value array;
11 | for (int i = 0; i < 5; ++i)
12 | {
13 | Json::Value user;
14 | user["id"] = i;
15 | user["name"] = "none";
16 | user["c_name"] = "张三";
17 | array.append(user);
18 | }
19 | json["rows"] = array;
20 | auto resp = HttpResponse::newHttpJsonResponse(json);
21 | assert(resp->jsonObject().get());
22 | callback(resp);
23 | }
24 |
--------------------------------------------------------------------------------
/drogon_ctl/templates/filter_cc.csp:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * [[filename]].cc
4 | *
5 | */
6 |
7 | #include "[[filename]].h"
8 |
9 | using namespace drogon;
10 | <%c++auto namespaceStr=@@.get("namespaceString");
11 | if(!namespaceStr.empty())
12 | $$<<"using namespace "<
14 |
15 | void [[className]]::doFilter(const HttpRequestPtr &req,
16 | FilterCallback &&fcb,
17 | FilterChainCallback &&fccb)
18 | {
19 | //Edit your logic here
20 | if (1)
21 | {
22 | //Passed
23 | fccb();
24 | return;
25 | }
26 | //Check failed
27 | auto res = drogon::HttpResponse::newHttpResponse();
28 | res->setStatusCode(k500InternalServerError);
29 | fcb(res);
30 | }
31 |
--------------------------------------------------------------------------------
/examples/simple_example/TestPlugin.h:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * TestPlugin.h
4 | *
5 | */
6 |
7 | #pragma once
8 |
9 | #include
10 | using namespace drogon;
11 |
12 | class TestPlugin : public Plugin
13 | {
14 | public:
15 | TestPlugin()
16 | {
17 | }
18 | /// This method must be called by drogon to initialize and start the plugin.
19 | /// It must be implemented by the user.
20 | virtual void initAndStart(const Json::Value &config) override;
21 |
22 | /// This method must be called by drogon to shutdown the plugin.
23 | /// It must be implemented by the user.
24 | virtual void shutdown() override;
25 |
26 | private:
27 | std::thread workThread_;
28 | bool stop_{false};
29 | int interval_;
30 | };
31 |
--------------------------------------------------------------------------------
/drogon_ctl/templates/filter_h.csp:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * [[filename]].h
4 | *
5 | */
6 |
7 | #pragma once
8 |
9 | #include
10 | using namespace drogon;
11 | <%c++
12 | auto namespaceVector=@@.get>("namespaceVector");
13 | if(namespaceVector.empty())
14 | $$<<"\n";
15 | for(auto &namespaceName:namespaceVector){%>
16 | namespace {%namespaceName%}
17 |
18 | {
19 | <%c++}
20 | $$<<"\n";%>
21 | class [[className]] : public HttpFilter<[[className]]>
22 | {
23 | public:
24 | [[className]]() {}
25 | virtual void doFilter(const HttpRequestPtr &req,
26 | FilterCallback &&fcb,
27 | FilterChainCallback &&fccb) override;
28 | };
29 |
30 | <%c++for(size_t i=0;i
31 | }
32 | <%c++}%>
--------------------------------------------------------------------------------
/lib/src/LocalHostFilter.cc:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * LocalHostFilter.cc
4 | * An Tao
5 | *
6 | * Copyright 2018, An Tao. All rights reserved.
7 | * https://github.com/an-tao/drogon
8 | * Use of this source code is governed by a MIT license
9 | * that can be found in the License file.
10 | *
11 | * Drogon
12 | *
13 | */
14 |
15 | #include "HttpResponseImpl.h"
16 | #include
17 | using namespace drogon;
18 | void LocalHostFilter::doFilter(const HttpRequestPtr &req,
19 | FilterCallback &&fcb,
20 | FilterChainCallback &&fccb)
21 | {
22 | if (req->peerAddr().isLoopbackIp())
23 | {
24 | fccb();
25 | return;
26 | }
27 | auto res = drogon::HttpResponse::newNotFoundResponse();
28 | fcb(res);
29 | }
30 |
--------------------------------------------------------------------------------
/unittest/SHA1Unittest.cpp:
--------------------------------------------------------------------------------
1 | #include "../lib/src/ssl_funcs/Sha1.h"
2 | #include
3 | #include
4 |
5 | TEST(SHA1Test, sha1)
6 | {
7 | unsigned char in[] =
8 | "1234567890123456789012345678901234567890123456789012345"
9 | "678901234567890123456789012345678901234567890";
10 | unsigned char out[SHA_DIGEST_LENGTH] = {0};
11 | SHA1(in, strlen((const char *)in), out);
12 | std::string outStr;
13 | outStr.resize(SHA_DIGEST_LENGTH * 2);
14 | for (int i = 0; i < SHA_DIGEST_LENGTH; ++i)
15 | sprintf((char *)(outStr.data() + i * 2), "%02x", out[i]);
16 | EXPECT_EQ(outStr, "fecfd28bbc9345891a66d7c1b8ff46e60192d284");
17 | }
18 |
19 | int main(int argc, char **argv)
20 | {
21 | testing::InitGoogleTest(&argc, argv);
22 | return RUN_ALL_TESTS();
23 | }
24 |
--------------------------------------------------------------------------------
/lib/src/IntranetIpFilter.cc:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * IntranetIpFilter.cc
4 | * An Tao
5 | *
6 | * Copyright 2018, An Tao. All rights reserved.
7 | * https://github.com/an-tao/drogon
8 | * Use of this source code is governed by a MIT license
9 | * that can be found in the License file.
10 | *
11 | * Drogon
12 | *
13 | */
14 |
15 | #include "HttpResponseImpl.h"
16 | #include
17 | using namespace drogon;
18 | void IntranetIpFilter::doFilter(const HttpRequestPtr &req,
19 | FilterCallback &&fcb,
20 | FilterChainCallback &&fccb)
21 | {
22 | if (req->peerAddr().isIntranetIp())
23 | {
24 | fccb();
25 | return;
26 | }
27 | auto res = drogon::HttpResponse::newNotFoundResponse();
28 | fcb(res);
29 | }
30 |
--------------------------------------------------------------------------------
/lib/inc/drogon/NotFound.h:
--------------------------------------------------------------------------------
1 | // this file is generated by program automatically,don't modify it!
2 |
3 | /**
4 | *
5 | * NotFound.h
6 | * An Tao
7 | *
8 | * Copyright 2018, An Tao. All rights reserved.
9 | * https://github.com/an-tao/drogon
10 | * Use of this source code is governed by a MIT license
11 | * that can be found in the License file.
12 | *
13 | * Drogon
14 | *
15 | */
16 |
17 | #include
18 | namespace drogon
19 | {
20 | /**
21 | * @brief This class is used by the drogon to generate the 404 page. Users don't
22 | * use this class directly.
23 | */
24 | class NotFound : public drogon::DrTemplate
25 | {
26 | public:
27 | NotFound(){};
28 | virtual ~NotFound(){};
29 | virtual std::string genText(const drogon::HttpViewData &) override;
30 | };
31 | } // namespace drogon
32 |
--------------------------------------------------------------------------------
/examples/simple_example/CustomCtrl.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | using namespace drogon;
4 | class CustomCtrl : public drogon::HttpController
5 | {
6 | public:
7 | METHOD_LIST_BEGIN
8 | // use METHOD_ADD to add your custom processing function here;
9 | METHOD_ADD(CustomCtrl::hello,
10 | "/{userName}",
11 | Get,
12 | "CustomHeaderFilter"); // path is /customctrl/{arg1}
13 | METHOD_LIST_END
14 |
15 | explicit CustomCtrl(const std::string &greetings) : greetings_(greetings)
16 | {
17 | }
18 |
19 | void hello(const HttpRequestPtr &req,
20 | std::function &&callback,
21 | const std::string &userName) const;
22 |
23 | private:
24 | std::string greetings_;
25 | };
26 |
--------------------------------------------------------------------------------
/lib/inc/drogon/LocalHostFilter.h:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * LocalHostFilter.h
4 | * An Tao
5 | *
6 | * Copyright 2018, An Tao. All rights reserved.
7 | * https://github.com/an-tao/drogon
8 | * Use of this source code is governed by a MIT license
9 | * that can be found in the License file.
10 | *
11 | * Drogon
12 | *
13 | */
14 |
15 | #pragma once
16 |
17 | #include
18 |
19 | namespace drogon
20 | {
21 | /**
22 | * @brief A filter that prohibit access from other hosts.
23 | */
24 | class LocalHostFilter : public HttpFilter
25 | {
26 | public:
27 | LocalHostFilter()
28 | {
29 | }
30 | virtual void doFilter(const HttpRequestPtr &req,
31 | FilterCallback &&fcb,
32 | FilterChainCallback &&fccb) override;
33 | };
34 | } // namespace drogon
35 |
--------------------------------------------------------------------------------
/lib/inc/drogon/IntranetIpFilter.h:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * IntranetIpFilter.h
4 | * An Tao
5 | *
6 | * Copyright 2018, An Tao. All rights reserved.
7 | * https://github.com/an-tao/drogon
8 | * Use of this source code is governed by a MIT license
9 | * that can be found in the License file.
10 | *
11 | * Drogon
12 | *
13 | */
14 |
15 | #pragma once
16 |
17 | #include
18 |
19 | namespace drogon
20 | {
21 | /**
22 | * @brief A filter that prohibit access from external networks
23 | */
24 | class IntranetIpFilter : public HttpFilter
25 | {
26 | public:
27 | IntranetIpFilter()
28 | {
29 | }
30 | virtual void doFilter(const HttpRequestPtr &req,
31 | FilterCallback &&fcb,
32 | FilterChainCallback &&fccb) override;
33 | };
34 | } // namespace drogon
35 |
--------------------------------------------------------------------------------
/drogon_ctl/help.h:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * help.h
4 | * An Tao
5 | *
6 | * Copyright 2018, An Tao. All rights reserved.
7 | * https://github.com/an-tao/drogon
8 | * Use of this source code is governed by a MIT license
9 | * that can be found in the License file.
10 | *
11 | * Drogon
12 | *
13 | */
14 |
15 | #pragma once
16 |
17 | #include
18 | #include "CommandHandler.h"
19 | using namespace drogon;
20 | namespace drogon_ctl
21 | {
22 | class help : public DrObject, public CommandHandler
23 | {
24 | public:
25 | virtual void handleCommand(std::vector ¶meters) override;
26 | virtual std::string script() override
27 | {
28 | return "display this message";
29 | }
30 | virtual bool isTopCommand() override
31 | {
32 | return true;
33 | }
34 | };
35 | } // namespace drogon_ctl
36 |
--------------------------------------------------------------------------------
/drogon_ctl/create_filter.h:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * create_filter.h
4 | * An Tao
5 | *
6 | * Copyright 2018, An Tao. All rights reserved.
7 | * https://github.com/an-tao/drogon
8 | * Use of this source code is governed by a MIT license
9 | * that can be found in the License file.
10 | *
11 | * Drogon
12 | *
13 | */
14 |
15 | #pragma once
16 |
17 | #include
18 | #include "CommandHandler.h"
19 | using namespace drogon;
20 | namespace drogon_ctl
21 | {
22 | class create_filter : public DrObject, public CommandHandler
23 | {
24 | public:
25 | virtual void handleCommand(std::vector ¶meters) override;
26 | virtual std::string script() override
27 | {
28 | return "create filter class files";
29 | }
30 |
31 | protected:
32 | std::string outputPath_{"."};
33 | };
34 | } // namespace drogon_ctl
35 |
--------------------------------------------------------------------------------
/drogon_ctl/create_plugin.h:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * create_plugin.h
4 | * An Tao
5 | *
6 | * Copyright 2018, An Tao. All rights reserved.
7 | * https://github.com/an-tao/drogon
8 | * Use of this source code is governed by a MIT license
9 | * that can be found in the License file.
10 | *
11 | * Drogon
12 | *
13 | */
14 |
15 | #pragma once
16 |
17 | #include
18 | #include "CommandHandler.h"
19 | using namespace drogon;
20 | namespace drogon_ctl
21 | {
22 | class create_plugin : public DrObject, public CommandHandler
23 | {
24 | public:
25 | virtual void handleCommand(std::vector ¶meters) override;
26 | virtual std::string script() override
27 | {
28 | return "create plugin class files";
29 | }
30 |
31 | protected:
32 | std::string outputPath_{"."};
33 | };
34 | } // namespace drogon_ctl
35 |
--------------------------------------------------------------------------------
/examples/simple_example/WebSocketTest.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | using namespace drogon;
4 | namespace example
5 | {
6 | class WebSocketTest : public drogon::WebSocketController
7 | {
8 | public:
9 | virtual void handleNewMessage(const WebSocketConnectionPtr &,
10 | std::string &&,
11 | const WebSocketMessageType &) override;
12 | virtual void handleConnectionClosed(
13 | const WebSocketConnectionPtr &) override;
14 | virtual void handleNewConnection(const HttpRequestPtr &,
15 | const WebSocketConnectionPtr &) override;
16 | WS_PATH_LIST_BEGIN
17 | // list path definations here;
18 | WS_PATH_ADD("/chat", "drogon::LocalHostFilter", Get);
19 | WS_PATH_LIST_END
20 | };
21 | } // namespace example
22 |
--------------------------------------------------------------------------------
/lib/src/ConfigLoader.h:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * ConfigLoader.h
4 | * An Tao
5 | *
6 | * Copyright 2018, An Tao. All rights reserved.
7 | * https://github.com/an-tao/drogon
8 | * Use of this source code is governed by a MIT license
9 | * that can be found in the License file.
10 | *
11 | * Drogon
12 | *
13 | */
14 |
15 | #pragma once
16 |
17 | #include
18 | #include
19 | #include
20 |
21 | namespace drogon
22 | {
23 | class ConfigLoader : public trantor::NonCopyable
24 | {
25 | public:
26 | explicit ConfigLoader(const std::string &configFile);
27 | ~ConfigLoader();
28 | const Json::Value &jsonValue() const
29 | {
30 | return configJsonRoot_;
31 | }
32 | void load();
33 |
34 | private:
35 | std::string configFile_;
36 | Json::Value configJsonRoot_;
37 | };
38 | } // namespace drogon
39 |
--------------------------------------------------------------------------------
/examples/simple_example/TestPlugin.cc:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * TestPlugin.cc
4 | *
5 | */
6 |
7 | #include "TestPlugin.h"
8 | #include
9 | #include
10 | using namespace std::chrono_literals;
11 |
12 | using namespace drogon;
13 |
14 | void TestPlugin::initAndStart(const Json::Value &config)
15 | {
16 | /// Initialize and start the plugin
17 | if (config.isNull())
18 | LOG_DEBUG << "Configuration not defined";
19 | interval_ = config.get("heartbeat_interval", 1).asInt();
20 | workThread_ = std::thread([this]() {
21 | while (!stop_)
22 | {
23 | LOG_DEBUG << "TestPlugin heartbeat!";
24 | std::this_thread::sleep_for(std::chrono::seconds(interval_));
25 | }
26 | });
27 | }
28 |
29 | void TestPlugin::shutdown()
30 | {
31 | /// Shutdown the plugin
32 | stop_ = true;
33 | workThread_.join();
34 | }
35 |
--------------------------------------------------------------------------------
/unittest/PubSubServiceUnittest.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | TEST(PubSubServiceTest, normal)
7 | {
8 | drogon::PubSubService service;
9 | auto id=service.subscribe("topic1",
10 | [](const std::string &topic, const std::string &message) {
11 | EXPECT_STREQ(topic.c_str(), "topic1");
12 | EXPECT_STREQ(message.c_str(), "hello world");
13 | });
14 | service.publish("topic1", "hello world");
15 | service.publish("topic2", "hello world");
16 | EXPECT_EQ(service.size(), 1);
17 | service.unsubscribe("topic1", id);
18 | EXPECT_EQ(service.size(), 0);
19 | }
20 |
21 | int main(int argc, char **argv)
22 | {
23 | testing::InitGoogleTest(&argc, argv);
24 | return RUN_ALL_TESTS();
25 | }
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM ubuntu:18.04
2 |
3 | RUN apt-get update -yqq \
4 | && apt-get install -yqq --no-install-recommends software-properties-common \
5 | sudo curl wget cmake pkg-config locales git gcc-8 g++-8 \
6 | openssl libssl-dev libjsoncpp-dev uuid-dev zlib1g-dev libc-ares-dev\
7 | postgresql-server-dev-all libmariadbclient-dev libsqlite3-dev \
8 | && rm -rf /var/lib/apt/lists/* \
9 | && locale-gen en_US.UTF-8
10 |
11 | ENV LANG=en_US.UTF-8 \
12 | LANGUAGE=en_US:en \
13 | LC_ALL=en_US.UTF-8 \
14 | CC=gcc-8 \
15 | CXX=g++-8 \
16 | AR=gcc-ar-8 \
17 | RANLIB=gcc-ranlib-8 \
18 | IROOT=/install
19 |
20 | ENV DROGON_ROOT="$IROOT/drogon"
21 |
22 | ADD https://api.github.com/repos/an-tao/drogon/git/refs/heads/master $IROOT/version.json
23 | RUN git clone https://github.com/an-tao/drogon $DROGON_ROOT
24 |
25 | WORKDIR $DROGON_ROOT
26 |
27 | RUN ./build.sh
28 |
--------------------------------------------------------------------------------
/drogon_ctl/CommandHandler.h:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * CommandHandler.h
4 | * An Tao
5 | *
6 | * Copyright 2018, An Tao. All rights reserved.
7 | * https://github.com/an-tao/drogon
8 | * Use of this source code is governed by a MIT license
9 | * that can be found in the License file.
10 | *
11 | * Drogon
12 | *
13 | */
14 |
15 | #pragma once
16 |
17 | #include
18 | #include
19 | #include
20 |
21 | class CommandHandler : public virtual drogon::DrObjectBase
22 | {
23 | public:
24 | virtual void handleCommand(std::vector ¶meters) = 0;
25 | virtual bool isTopCommand()
26 | {
27 | return false;
28 | }
29 | virtual std::string script()
30 | {
31 | return "";
32 | }
33 | virtual std::string detail()
34 | {
35 | return "";
36 | }
37 | virtual ~CommandHandler()
38 | {
39 | }
40 | };
41 |
--------------------------------------------------------------------------------
/drogon_ctl/create_project.h:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * create_project.h
4 | * An Tao
5 | *
6 | * Copyright 2018, An Tao. All rights reserved.
7 | * https://github.com/an-tao/drogon
8 | * Use of this source code is governed by a MIT license
9 | * that can be found in the License file.
10 | *
11 | * Drogon
12 | *
13 | */
14 | #pragma once
15 |
16 | #include
17 | #include "CommandHandler.h"
18 | using namespace drogon;
19 | namespace drogon_ctl
20 | {
21 | class create_project : public DrObject, public CommandHandler
22 | {
23 | public:
24 | virtual void handleCommand(std::vector ¶meters) override;
25 | virtual std::string script() override
26 | {
27 | return "create a project";
28 | }
29 |
30 | protected:
31 | std::string outputPath_{"."};
32 | void createProject(const std::string &projectName);
33 | };
34 | } // namespace drogon_ctl
35 |
--------------------------------------------------------------------------------
/examples/simple_example/WebSocketTest.cc:
--------------------------------------------------------------------------------
1 | #include "WebSocketTest.h"
2 | using namespace example;
3 | void WebSocketTest::handleNewMessage(const WebSocketConnectionPtr &wsConnPtr,
4 | std::string &&message,
5 | const WebSocketMessageType &type)
6 | {
7 | // write your application logic here
8 | LOG_DEBUG << "new websocket message:" << message;
9 | if (type == WebSocketMessageType::Ping)
10 | {
11 | LOG_DEBUG << "recv a ping";
12 | }
13 | }
14 |
15 | void WebSocketTest::handleConnectionClosed(const WebSocketConnectionPtr &)
16 | {
17 | LOG_DEBUG << "websocket closed!";
18 | }
19 |
20 | void WebSocketTest::handleNewConnection(const HttpRequestPtr &,
21 | const WebSocketConnectionPtr &conn)
22 | {
23 | LOG_DEBUG << "new websocket connection!";
24 | conn->send("haha!!!");
25 | }
26 |
--------------------------------------------------------------------------------
/drogon_ctl/version.h:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * version.h
4 | * An Tao
5 | *
6 | * Copyright 2018, An Tao. All rights reserved.
7 | * https://github.com/an-tao/drogon
8 | * Use of this source code is governed by a MIT license
9 | * that can be found in the License file.
10 | *
11 | * Drogon
12 | *
13 | */
14 |
15 | #pragma once
16 |
17 | #include
18 | #include "CommandHandler.h"
19 | using namespace drogon;
20 | namespace drogon_ctl
21 | {
22 | class version : public DrObject, public CommandHandler
23 | {
24 | public:
25 | virtual void handleCommand(std::vector ¶meters) override;
26 | virtual std::string script() override
27 | {
28 | return "display version of this tool";
29 | }
30 | virtual bool isTopCommand() override
31 | {
32 | return true;
33 | }
34 | version()
35 | {
36 | }
37 | };
38 | } // namespace drogon_ctl
39 |
--------------------------------------------------------------------------------
/cmake_modules/Findcoz-profiler.cmake:
--------------------------------------------------------------------------------
1 | find_path(COZ_INCLUDE_DIRS NAMES coz.h)
2 |
3 | find_library(COZ_LIBRARIES NAMES coz PATH_SUFFIXES coz-profiler)
4 |
5 | include(FindPackageHandleStandardArgs)
6 | find_package_handle_standard_args(coz-profiler
7 | DEFAULT_MSG
8 | COZ_LIBRARIES
9 | COZ_INCLUDE_DIRS)
10 |
11 | if(COZ-PROFILER_FOUND)
12 | add_library(coz::coz INTERFACE IMPORTED)
13 | set_target_properties(coz::coz
14 | PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
15 | ${COZ_INCLUDE_DIRS}
16 | INTERFACE_LINK_LIBRARIES
17 | ${COZ_LIBRARIES})
18 | else(COZ-PROFILER_FOUND)
19 | set(COZ_LIBRARIES)
20 | set(COZ_INCLUDE_DIRS)
21 | endif(COZ-PROFILER_FOUND)
22 |
23 | mark_as_advanced(COZ_INCLUDE_DIRS COZ_LIBRARIES)
24 |
--------------------------------------------------------------------------------
/lib/src/HttpFileUploadRequest.cc:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * HttpFileUploadRequest.cc
4 | * An Tao
5 | *
6 | * Copyright 2018, An Tao. All rights reserved.
7 | * https://github.com/an-tao/drogon
8 | * Use of this source code is governed by a MIT license
9 | * that can be found in the License file.
10 | *
11 | * Drogon
12 | *
13 | */
14 |
15 | #include "HttpFileUploadRequest.h"
16 | #include
17 | #include
18 |
19 | using namespace drogon;
20 |
21 | HttpFileUploadRequest::HttpFileUploadRequest(
22 | const std::vector &files)
23 | : HttpRequestImpl(nullptr),
24 | boundary_(utils::genRandomString(32)),
25 | files_(files)
26 | {
27 | setMethod(drogon::Post);
28 | setVersion(drogon::Version::kHttp11);
29 | setContentType("Content-Type: multipart/form-data; boundary=" + boundary_ +
30 | "\r\n");
31 | contentType_ = CT_MULTIPART_FORM_DATA;
32 | }
--------------------------------------------------------------------------------
/examples/simple_example/TestController.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 | using namespace drogon;
5 | namespace example
6 | {
7 | class TestController : public drogon::HttpSimpleController
8 | {
9 | public:
10 | virtual void asyncHandleHttpRequest(
11 | const HttpRequestPtr &req,
12 | std::function &&callback) override;
13 | PATH_LIST_BEGIN
14 | // list path definations here;
15 | // PATH_ADD("/path","filter1","filter2",...);
16 | PATH_ADD("/", Get);
17 | PATH_ADD("/Test", "nonFilter");
18 | PATH_ADD("/tpost", Post, Options);
19 | PATH_ADD("/slow", "TimeFilter", Get);
20 | PATH_LIST_END
21 | TestController()
22 | {
23 | LOG_DEBUG << "TestController constructor";
24 | }
25 |
26 | private:
27 | drogon::IOThreadStorage threadIndex_;
28 | };
29 | } // namespace example
30 |
--------------------------------------------------------------------------------
/lib/src/HttpFileUploadRequest.h:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * HttpFileUploadRequest.h
4 | * An Tao
5 | *
6 | * Copyright 2018, An Tao. All rights reserved.
7 | * https://github.com/an-tao/drogon
8 | * Use of this source code is governed by a MIT license
9 | * that can be found in the License file.
10 | *
11 | * Drogon
12 | *
13 | */
14 |
15 | #pragma once
16 | #include "HttpRequestImpl.h"
17 | #include
18 | #include
19 |
20 | namespace drogon
21 | {
22 | class HttpFileUploadRequest : public HttpRequestImpl
23 | {
24 | public:
25 | const std::string &boundary() const
26 | {
27 | return boundary_;
28 | }
29 | const std::vector &files() const
30 | {
31 | return files_;
32 | }
33 | explicit HttpFileUploadRequest(const std::vector &files);
34 |
35 | private:
36 | std::string boundary_;
37 | std::vector files_;
38 | };
39 |
40 | } // namespace drogon
41 |
--------------------------------------------------------------------------------
/unittest/GzipUnittest.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | using namespace drogon::utils;
6 | TEST(GzipTest, shortText)
7 | {
8 | std::string source{"123中文顶替要枯械"};
9 | auto compressed = gzipCompress(source.data(), source.length());
10 | auto decompressed = gzipDecompress(compressed.data(), compressed.length());
11 | EXPECT_EQ(source, decompressed);
12 | }
13 |
14 | TEST(GzipTest, longText)
15 | {
16 | std::string source;
17 | for (size_t i = 0; i < 100000; i++)
18 | {
19 | source.append(std::to_string(i));
20 | }
21 | auto compressed = gzipCompress(source.data(), source.length());
22 | auto decompressed = gzipDecompress(compressed.data(), compressed.length());
23 | EXPECT_EQ(source, decompressed);
24 | }
25 |
26 | int main(int argc, char **argv)
27 | {
28 | testing::InitGoogleTest(&argc, argv);
29 | return RUN_ALL_TESTS();
30 | }
--------------------------------------------------------------------------------
/drogon_ctl/templates/plugin_h.csp:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * [[filename]].h
4 | *
5 | */
6 |
7 | #pragma once
8 |
9 | #include
10 | <%c++
11 | auto namespaceVector=@@.get>("namespaceVector");
12 | if(namespaceVector.empty())
13 | $$<<"\n";
14 | for(auto &namespaceName:namespaceVector){%>
15 | namespace {%namespaceName%}
16 |
17 | {
18 | <%c++}
19 | $$<<"\n";%>
20 | class [[className]] : public drogon::Plugin<[[className]]>
21 | {
22 | public:
23 | [[className]]() {}
24 | /// This method must be called by drogon to initialize and start the plugin.
25 | /// It must be implemented by the user.
26 | virtual void initAndStart(const Json::Value &config) override;
27 |
28 | /// This method must be called by drogon to shutdown the plugin.
29 | /// It must be implemented by the user.
30 | virtual void shutdown() override;
31 | };
32 |
33 | <%c++for(size_t i=0;i
34 | }
35 | <%c++}%>
--------------------------------------------------------------------------------
/lib/src/PluginsManager.h:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * PluginsManager.h
4 | * An Tao
5 | *
6 | * Copyright 2018, An Tao. All rights reserved.
7 | * https://github.com/an-tao/drogon
8 | * Use of this source code is governed by a MIT license
9 | * that can be found in the License file.
10 | *
11 | * Drogon
12 | *
13 | */
14 |
15 | #pragma once
16 | #include
17 | #include