This commit is contained in:
Aaron Kimbrell
2025-10-06 19:15:55 -05:00
parent 62ac65c520
commit 5453d163a3
9 changed files with 258 additions and 2 deletions

View File

@@ -13,7 +13,6 @@ namespace Game {
}
namespace {
const char* jsonContentType = "Content-Type: application/json\r\n";
const std::string wsSubscribed = "{\"status\":\"subscribed\"}";
const std::string wsUnsubscribed = "{\"status\":\"unsubscribed\"}";
std::map<std::pair<eHTTPMethod, std::string>, HTTPRoute> g_HTTPRoutes;
@@ -73,7 +72,7 @@ void HandleHTTPMessage(mg_connection* connection, const mg_http_message* http_ms
reply.status = eHTTPStatusCode::UNAUTHORIZED;
reply.message = "{\"error\":\"Unauthorized\"}";
}
mg_http_reply(connection, static_cast<int>(reply.status), jsonContentType, reply.message.c_str());
mg_http_reply(connection, static_cast<int>(reply.status), reply.contentType.c_str(), reply.message.c_str());
}

View File

@@ -20,10 +20,36 @@ enum class eHTTPMethod;
// Forward declaration for mongoose manager
typedef struct mg_mgr mg_mgr;
namespace ContentType {
const std::string JSON = "Content-Type: application/json\r\n";
const std::string HTML = "Content-Type: text/html\r\n";
const std::string PLAIN = "Content-Type: text/plain\r\n";
const std::string CSS = "Content-Type: text/css\r\n";
const std::string JAVASCRIPT = "Content-Type: application/javascript\r\n";
const std::string ICO = "Content-Type: image/x-icon\r\n";
const std::string PNG = "Content-Type: image/png\r\n";
const std::string SVG = "Content-Type: image/svg+xml\r\n";
const std::string JPG = "Content-Type: image/jpeg\r\n";
const std::string GIF = "Content-Type: image/gif\r\n";
const std::string WEBP = "Content-Type: image/webp\r\n";
const std::string MP4 = "Content-Type: video/mp4\r\n";
const std::string OGG = "Content-Type: audio/ogg\r\n";
const std::string MP3 = "Content-Type: audio/mpeg\r\n";
const std::string BINARY = "Content-Type: application/octet-stream\r\n";
const std::string FORM = "Content-Type: application/x-www-form-urlencoded\r\n";
const std::string MULTIPART = "Content-Type: multipart/form-data\r\n";
const std::string ZIP = "Content-Type: application/zip\r\n";
const std::string PDF = "Content-Type: application/pdf\r\n";
const std::string XML = "Content-Type: application/xml\r\n";
const std::string CSV = "Content-Type: text/csv\r\n";
const std::string YAML = "Content-Type: application/x-yaml\r\n";
}
// For passing HTTP messages between functions
struct HTTPReply {
eHTTPStatusCode status = eHTTPStatusCode::NOT_FOUND;
std::string message = "{\"error\":\"Not Found\"}";
std::string contentType = ContentType::JSON;
};
// HTTP route structure