-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRoute-inl.h
40 lines (31 loc) · 1021 Bytes
/
Route-inl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
namespace shitty {
inline const std::string& Route::path() const {
return path_;
}
namespace detail {
// Class to make per-request proxy objects so that static handlers can be
// accessed as if they were per-request factory-served routes.
class StaticRouteProxy: public RequestHandler {
public:
explicit StaticRouteProxy(StaticResponder* static_responder):
static_responder_(static_responder)
{}
void onRequest(Request&& request, ServerStream *stream) override {
static_responder_->onRequest(std::move(request), stream);
}
private:
StaticResponder* static_responder_;
};
class StaticRouteHandlerFactory: public RequestHandlerFactory {
public:
explicit StaticRouteHandlerFactory(StaticResponder* responder):
responder_(responder)
{}
std::unique_ptr<RequestHandler> getHandler() const override {
return std::make_unique<StaticRouteProxy>(responder_);
}
private:
StaticResponder *responder_;
};
} // namespace detail
} // namespace shitty