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> |
Zhenkai Zhu | d942922 | 2013-02-25 22:34:09 -0800 | [diff] [blame] | 16 | #include <QDir> |
Zhenkai Zhu | a9a7e1d | 2013-02-25 18:29:07 -0800 | [diff] [blame] | 17 | |
| 18 | namespace http { |
| 19 | namespace server { |
| 20 | |
| 21 | struct reply; |
| 22 | struct request; |
| 23 | |
| 24 | /// The common handler for all incoming requests. |
| 25 | class request_handler |
| 26 | : private boost::noncopyable |
| 27 | { |
| 28 | public: |
| 29 | /// Construct with a directory containing files to be served. |
| 30 | explicit request_handler(const std::string& doc_root); |
| 31 | |
| 32 | /// Handle a request and produce a reply. |
| 33 | void handle_request(const request& req, reply& rep); |
| 34 | |
| 35 | private: |
| 36 | /// The directory containing the files to be served. |
Zhenkai Zhu | d942922 | 2013-02-25 22:34:09 -0800 | [diff] [blame] | 37 | QDir doc_root_; |
Zhenkai Zhu | a9a7e1d | 2013-02-25 18:29:07 -0800 | [diff] [blame] | 38 | |
| 39 | /// Perform URL-decoding on a string. Returns false if the encoding was |
| 40 | /// invalid. |
| 41 | static bool url_decode(const std::string& in, std::string& out); |
| 42 | }; |
| 43 | |
| 44 | } // namespace server |
| 45 | } // namespace http |
| 46 | |
| 47 | #endif // HTTP_REQUEST_HANDLER_HPP |