/src/wt/src/http/RequestHandler.h
Line | Count | Source |
1 | | // This may look like C code, but it's really -*- C++ -*- |
2 | | /* |
3 | | * Copyright (C) 2008 Emweb bv, Herent, Belgium. |
4 | | * |
5 | | * All rights reserved. |
6 | | */ |
7 | | // |
8 | | // request_handler.hpp |
9 | | // ~~~~~~~~~~~~~~~~~~~ |
10 | | // |
11 | | // Copyright (c) 2003-2006 Christopher M. Kohlhoff (chris at kohlhoff dot com) |
12 | | // |
13 | | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
14 | | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
15 | | // |
16 | | |
17 | | #ifndef HTTP_REQUEST_HANDLER_HPP |
18 | | #define HTTP_REQUEST_HANDLER_HPP |
19 | | |
20 | | #include <string> |
21 | | |
22 | | #include "Configuration.h" |
23 | | #include "SessionProcessManager.h" |
24 | | #include "WtReply.h" |
25 | | #include "AccessLogger.h" |
26 | | #include "../web/Configuration.h" |
27 | | |
28 | | namespace http { |
29 | | namespace server { |
30 | | |
31 | | class Configuration; |
32 | | class Request; |
33 | | |
34 | | /// The common handler for all incoming requests. |
35 | | class RequestHandler |
36 | | { |
37 | | public: |
38 | | /// Construct with a directory containing files to be served. |
39 | | explicit RequestHandler(const Configuration &config, |
40 | | const Wt::Configuration& wtConfig, |
41 | | AccessLogger& logger); |
42 | | |
43 | | /// Handle a request and produce a reply. |
44 | | ReplyPtr handleRequest(Request& req, ReplyPtr& lastWtReply, |
45 | | ReplyPtr& lastProxyReply, |
46 | | ReplyPtr& lastStaticReply); |
47 | | |
48 | | RequestHandler(const RequestHandler&) = delete; |
49 | | RequestHandler& operator=(const RequestHandler&) = delete; |
50 | | |
51 | | const std::string getErrorRoot() const |
52 | 0 | { |
53 | 0 | return config_.errRoot(); |
54 | 0 | } |
55 | | |
56 | 0 | AccessLogger& logger() const { return logger_; } |
57 | | |
58 | | void setSessionManager(SessionProcessManager *sessionManager); |
59 | | |
60 | 0 | const Wt::Configuration* wtConfig() const { return &wtConfig_; } |
61 | | |
62 | | private: |
63 | | /// The server configuration |
64 | | const Configuration &config_; |
65 | | /// The Wt configuration |
66 | | const Wt::Configuration &wtConfig_; |
67 | | /// The logger |
68 | | AccessLogger& logger_; |
69 | | /// The session manager for dedicated processes |
70 | | SessionProcessManager *sessionManager_; |
71 | | |
72 | | /// Perform URL-decoding on a string and separates in path and |
73 | | /// query. Returns false if the encoding was invalid. |
74 | | static bool url_decode(const buffer_string& in, std::string& path, |
75 | | std::string& query); |
76 | | |
77 | | static bool matchesPath(const std::string& path, |
78 | | const std::string& prefix, |
79 | | bool matchAfterSlash); |
80 | | |
81 | | }; |
82 | | |
83 | | } // namespace server |
84 | | } // namespace http |
85 | | |
86 | | #endif // HTTP_REQUEST_HANDLER_HPP |