HttpServer.h 1015 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #ifndef HTTPSERVER_H
  2. #define HTTPSERVER_H
  3. #include "HttpPostData.h"
  4. #include <functional>
  5. #include <memory>
  6. #include <vector>
  7. namespace Http {
  8. class HttpServerImpl;
  9. class HttpServer
  10. {
  11. public:
  12. struct HttpReply
  13. {
  14. struct Status
  15. {
  16. enum type
  17. {
  18. Ok = 200,
  19. Created = 201,
  20. Accepted = 202,
  21. NoContent = 204,
  22. MultipleChoices = 300,
  23. MovedPermanently = 301,
  24. MovedTemporarily = 302,
  25. NotModified = 304,
  26. BadRequest = 400,
  27. Unauthorized = 401,
  28. Forbidden = 403,
  29. NotFound = 404,
  30. InternalServerError = 500,
  31. NotImplemented = 501,
  32. BadGateway = 502,
  33. ServiceUnavailable = 503
  34. };
  35. };
  36. Status::type status;
  37. std::string content;
  38. };
  39. public:
  40. typedef std::function<HttpReply(const std::string&, const std::vector<HttpPostData>&)> CallbackMethod;
  41. public:
  42. HttpServer(unsigned short port, CallbackMethod callback);
  43. ~HttpServer();
  44. void Wait();
  45. private:
  46. std::unique_ptr<HttpServerImpl> m_pHttpServerImpl;
  47. };
  48. } // namespace Http
  49. #endif // HTTPSERVER_H