request_handler.hpp 1.2 KB

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