1
0

httpsServer.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #ifndef CPR_TEST_HTTPS_SERVER_H
  2. #define CPR_TEST_HTTPS_SERVER_H
  3. #include <memory>
  4. #include <string>
  5. #include "abstractServer.hpp"
  6. #include "cpr/cpr.h"
  7. #include "mongoose.h"
  8. #include <cpr/filesystem.h>
  9. namespace cpr {
  10. class HttpsServer : public AbstractServer {
  11. private:
  12. // We don't use fs::path here, as this leads to problems using windows
  13. const std::string baseDirPath;
  14. const std::string sslCertFileName;
  15. const std::string sslKeyFileName;
  16. struct mg_tls_opts tlsOpts;
  17. public:
  18. explicit HttpsServer(fs::path&& baseDirPath, fs::path&& sslCertFileName, fs::path&& sslKeyFileName);
  19. ~HttpsServer() override = default;
  20. std::string GetBaseUrl() override;
  21. uint16_t GetPort() override;
  22. void OnRequest(mg_connection* conn, mg_http_message* msg) override;
  23. static void OnRequestHello(mg_connection* conn, mg_http_message* msg);
  24. static void OnRequestNotFound(mg_connection* conn, mg_http_message* msg);
  25. const std::string& getBaseDirPath() const;
  26. const std::string& getSslCertFileName() const;
  27. const std::string& getSslKeyFileName() const;
  28. protected:
  29. mg_connection* initServer(mg_mgr* mgr, mg_event_handler_t event_handler) override;
  30. void acceptConnection(mg_connection* conn) override;
  31. };
  32. } // namespace cpr
  33. #endif