Zhenkai Zhu | a9a7e1d | 2013-02-25 18:29:07 -0800 | [diff] [blame^] | 1 | // |
| 2 | // request_handler.hpp |
| 3 | // ~~~~~~~~~~~~~~~~~~~ |
| 4 | // |
| 5 | // Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com) |
| 6 | // |
| 7 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 8 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 9 | // |
| 10 | |
| 11 | #ifndef HTTP_REQUEST_HANDLER_HPP |
| 12 | #define HTTP_REQUEST_HANDLER_HPP |
| 13 | |
| 14 | #include <string> |
| 15 | #include <boost/noncopyable.hpp> |
| 16 | |
| 17 | namespace http { |
| 18 | namespace server { |
| 19 | |
| 20 | struct reply; |
| 21 | struct request; |
| 22 | |
| 23 | /// The common handler for all incoming requests. |
| 24 | class request_handler |
| 25 | : private boost::noncopyable |
| 26 | { |
| 27 | public: |
| 28 | /// Construct with a directory containing files to be served. |
| 29 | explicit request_handler(const std::string& doc_root); |
| 30 | |
| 31 | /// Handle a request and produce a reply. |
| 32 | void handle_request(const request& req, reply& rep); |
| 33 | |
| 34 | private: |
| 35 | /// The directory containing the files to be served. |
| 36 | std::string doc_root_; |
| 37 | |
| 38 | /// Perform URL-decoding on a string. Returns false if the encoding was |
| 39 | /// invalid. |
| 40 | static bool url_decode(const std::string& in, std::string& out); |
| 41 | }; |
| 42 | |
| 43 | } // namespace server |
| 44 | } // namespace http |
| 45 | |
| 46 | #endif // HTTP_REQUEST_HANDLER_HPP |