request_handler.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //
  2. // request_handler.hpp
  3. // ~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2010 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. #ifndef EXPERIMENTAL_HTTP_SERVER_HTTP_REQUEST_HANDLER_H
  11. #define EXPERIMENTAL_HTTP_SERVER_HTTP_REQUEST_HANDLER_H
  12. #include <string>
  13. #include <boost/noncopyable.hpp>
  14. namespace http_server {
  15. struct reply;
  16. struct request;
  17. /// The common handler for all incoming requests.
  18. class request_handler: private boost::noncopyable
  19. {
  20. public:
  21. /// Construct with a directory containing files to be served.
  22. explicit request_handler(const std::string& doc_root);
  23. /// Handle a request and produce a reply.
  24. void handle_request(const request& req, reply& rep);
  25. private:
  26. /// The directory containing the files to be served.
  27. std::string doc_root_;
  28. /// Perform URL-decoding on a string. Returns false if the encoding was
  29. /// invalid.
  30. static bool url_decode(const std::string& in, std::string& out);
  31. };
  32. } // namespace http_server
  33. #endif // EXPERIMENTAL_HTTP_SERVER_HTTP_REQUEST_HANDLER_H