drogon
C++14/17-based HTTP application framework
Loading...
Searching...
No Matches
Redirector.h
Go to the documentation of this file.
1
13
14#pragma once
15
17#include <drogon/HttpRequest.h>
18#include <vector>
19
20namespace drogon
21{
22namespace plugin
23{
32 std::function<bool(const drogon::HttpRequestPtr &,
33 std::string &, //"http://" or "https://"
34 std::string &, // host
35 bool &)>; // path changed or not
43using PathRewriteHandler = std::function<bool(const drogon::HttpRequestPtr &)>;
44
52using ForwardHandler = std::function<void(const drogon::HttpRequestPtr &)>;
53
71class DROGON_EXPORT Redirector : public drogon::Plugin<Redirector>,
72 public std::enable_shared_from_this<Redirector>
73{
74 public:
75 Redirector()
76 {
77 }
78
79 void initAndStart(const Json::Value &config) override;
80 void shutdown() override;
81
82 void registerRedirectHandler(RedirectorHandler &&handler)
83 {
84 handlers_.emplace_back(std::move(handler));
85 }
86
87 void registerRedirectHandler(const RedirectorHandler &handler)
88 {
89 handlers_.emplace_back(handler);
90 }
91
92 void registerPathRewriteHandler(PathRewriteHandler &&handler)
93 {
94 pathRewriteHandlers_.emplace_back(std::move(handler));
95 }
96
97 void registerPathRewriteHandler(const PathRewriteHandler &handler)
98 {
99 pathRewriteHandlers_.emplace_back(handler);
100 }
101
102 void registerForwardHandler(ForwardHandler &&handler)
103 {
104 forwardHandlers_.emplace_back(std::move(handler));
105 }
106
107 void registerForwardHandler(const ForwardHandler &handler)
108 {
109 forwardHandlers_.emplace_back(handler);
110 }
111
112 private:
113 std::vector<RedirectorHandler> handlers_;
114 std::vector<PathRewriteHandler> pathRewriteHandlers_;
115 std::vector<ForwardHandler> forwardHandlers_;
116};
117
118} // namespace plugin
119} // namespace drogon
std::function< bool(const drogon::HttpRequestPtr &)> PathRewriteHandler
The PathRewriteHandler is a function object that can be registered to the Redirector plugin....
Definition Redirector.h:43
std::function< bool(const drogon::HttpRequestPtr &, std::string &, std::string &, bool &)> RedirectorHandler
The RedirectorHandler is a function object that can be registered to the Redirector plugin....
Definition Redirector.h:31
std::function< void(const drogon::HttpRequestPtr &)> ForwardHandler
The ForwardHandler is a function object that can be registered to the Redirector plugin....
Definition Redirector.h:52
The reflection base class for plugins.
Definition Plugin.h:132
void shutdown() override
void initAndStart(const Json::Value &config) override
Drogon Test is a minimal effort test framework developed because the major C++ test frameworks doesn'...
Definition Attribute.h:23