httpServer.hpp 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #ifndef CPR_TEST_HTTP_SERVER_H
  2. #define CPR_TEST_HTTP_SERVER_H
  3. #include <memory>
  4. #include <string>
  5. #include "abstractServer.hpp"
  6. #include "cpr/cpr.h"
  7. #include "mongoose.h"
  8. namespace cpr {
  9. class HttpServer : public AbstractServer {
  10. public:
  11. ~HttpServer() override = default;
  12. std::string GetBaseUrl() override;
  13. uint16_t GetPort() override;
  14. void OnRequest(mg_connection* conn, mg_http_message* msg) override;
  15. private:
  16. static void OnRequestHello(mg_connection* conn, mg_http_message* msg);
  17. static void OnRequestRoot(mg_connection* conn, mg_http_message* msg);
  18. static void OnRequestOptions(mg_connection* conn, mg_http_message* msg);
  19. static void OnRequestNotFound(mg_connection* conn, mg_http_message* msg);
  20. static void OnRequestTimeout(mg_connection* conn, mg_http_message* msg);
  21. static void OnRequestLongTimeout(mg_connection* conn, mg_http_message* msg);
  22. static void OnRequestLowSpeedTimeout(mg_connection* conn, mg_http_message* msg, TimerArg* arg);
  23. static void OnRequestLowSpeed(mg_connection* conn, mg_http_message* msg, mg_mgr* mgr);
  24. static void OnRequestLowSpeedBytes(mg_connection* conn, mg_http_message* msg, TimerArg* arg);
  25. static void OnRequestBasicCookies(mg_connection* conn, mg_http_message* msg);
  26. static void OnRequestEmptyCookies(mg_connection* conn, mg_http_message* msg);
  27. static void OnRequestCookiesReflect(mg_connection* conn, mg_http_message* msg);
  28. static void OnRequestRedirectionWithChangingCookies(mg_connection* conn, mg_http_message* msg);
  29. static void OnRequestBasicAuth(mg_connection* conn, mg_http_message* msg);
  30. static void OnRequestBearerAuth(mg_connection* conn, mg_http_message* msg);
  31. static void OnRequestBasicJson(mg_connection* conn, mg_http_message* msg);
  32. static void OnRequestHeaderReflect(mg_connection* conn, mg_http_message* msg);
  33. static void OnRequestTempRedirect(mg_connection* conn, mg_http_message* msg);
  34. static void OnRequestPermRedirect(mg_connection* conn, mg_http_message* msg);
  35. static void OnRequestResolvePermRedirect(mg_connection* conn, mg_http_message* msg);
  36. static void OnRequestTwoRedirects(mg_connection* conn, mg_http_message* msg);
  37. static void OnRequestUrlPost(mg_connection* conn, mg_http_message* msg);
  38. static void OnRequestPostReflect(mg_connection* conn, mg_http_message* msg);
  39. static void OnRequestBodyGet(mg_connection* conn, mg_http_message* msg);
  40. static void OnRequestJsonPost(mg_connection* conn, mg_http_message* msg);
  41. static void OnRequestFormPost(mg_connection* conn, mg_http_message* msg);
  42. static void OnRequestDelete(mg_connection* conn, mg_http_message* msg);
  43. static void OnRequestDeleteNotAllowed(mg_connection* conn, mg_http_message* msg);
  44. static void OnRequestPut(mg_connection* conn, mg_http_message* msg);
  45. static void OnRequestPutNotAllowed(mg_connection* conn, mg_http_message* msg);
  46. static void OnRequestPatch(mg_connection* conn, mg_http_message* msg);
  47. static void OnRequestPatchNotAllowed(mg_connection* conn, mg_http_message* msg);
  48. static void OnRequestDownloadGzip(mg_connection* conn, mg_http_message* msg);
  49. static void OnRequestLocalPort(mg_connection* conn, mg_http_message* msg);
  50. static void OnRequestCheckAcceptEncoding(mg_connection* conn, mg_http_message* msg);
  51. static void OnRequestCheckExpect100Continue(mg_connection* conn, mg_http_message* msg);
  52. protected:
  53. mg_connection* initServer(mg_mgr* mgr, mg_event_handler_t event_handler) override;
  54. void acceptConnection(mg_connection* conn) override;
  55. };
  56. } // namespace cpr
  57. #endif