From b9445e6796de8e26a9b9b48f090b9b125492dd61 Mon Sep 17 00:00:00 2001 From: Andreev Gregory Date: Tue, 6 Aug 2024 12:33:20 +0300 Subject: [PATCH] Connected fron t to back --- assets/html/chat.html | 4 ++-- assets/html/list-rooms.html | 4 ++-- assets/html/profile.html | 6 ++--- assets/html/registration.html | 4 ++-- .../http_structures/client_request_parse.cpp | 2 ++ src/web_chat/main.cpp | 24 ++++++++++++++----- 6 files changed, 29 insertions(+), 15 deletions(-) diff --git a/assets/html/chat.html b/assets/html/chat.html index 504f155..809d6b4 100644 --- a/assets/html/chat.html +++ b/assets/html/chat.html @@ -4,7 +4,7 @@ Веб-Чат - +
@@ -20,6 +20,6 @@
- + diff --git a/assets/html/list-rooms.html b/assets/html/list-rooms.html index 2c84e99..390359f 100644 --- a/assets/html/list-rooms.html +++ b/assets/html/list-rooms.html @@ -4,7 +4,7 @@ Список Чат-Комнат - +
@@ -47,6 +47,6 @@
- + diff --git a/assets/html/profile.html b/assets/html/profile.html index 4e33a4b..31523d2 100644 --- a/assets/html/profile.html +++ b/assets/html/profile.html @@ -2,7 +2,7 @@ - + Профиль @@ -13,7 +13,7 @@
-
+

@@ -30,7 +30,7 @@
- + diff --git a/assets/html/registration.html b/assets/html/registration.html index d82da21..5cd0bed 100644 --- a/assets/html/registration.html +++ b/assets/html/registration.html @@ -4,7 +4,7 @@ Страница Регистрации - + @@ -17,7 +17,7 @@ - + diff --git a/src/http_server/engine_engine_number_9/http_structures/client_request_parse.cpp b/src/http_server/engine_engine_number_9/http_structures/client_request_parse.cpp index a4d56ec..bce7ce2 100644 --- a/src/http_server/engine_engine_number_9/http_structures/client_request_parse.cpp +++ b/src/http_server/engine_engine_number_9/http_structures/client_request_parse.cpp @@ -99,6 +99,8 @@ namespace een9 { if (p.first == "Content-Length") { collecting_body = res.has_body = true; body_size = std::stoull(p.second); + if (body_size > 100000000) + THROW("Message content is too big"); res.body.reserve(body_size); } } diff --git a/src/web_chat/main.cpp b/src/web_chat/main.cpp index df3f943..f892ee4 100644 --- a/src/web_chat/main.cpp +++ b/src/web_chat/main.cpp @@ -57,6 +57,9 @@ int main(int argc, char** argv){ een9::StaticAssetManagerRule{assets_dir + "/html", "/assets/html", {{".html", "text/html"}} }, een9::StaticAssetManagerRule{assets_dir + "/css", "/assets/css", {{".css", "text/css"}} }, een9::StaticAssetManagerRule{assets_dir + "/js", "/assets/js", {{".js", "text/js"}} }, + een9::StaticAssetManagerRule{assets_dir + "/img", "/assets/img", { + {".jpg", "image/jpg"}, {".png", "image/png"}, {".svg", "image/svg+xml"} + } }, }); een9::MainloopParameters params; @@ -68,15 +71,24 @@ int main(int argc, char** argv){ std::string text = unsafe_client_request_stringification(req); return een9::form_http_server_response_200("text/plain", text); } - if (req.uri_path == "/" || req.uri_path == "/index.html") { - for (auto& p: een9::split_html_query(req.uri_query)) { - printf("Query: %s = %s\n", p.first.c_str(), p.second.c_str()); - } - printf(""); - ret = samI.get_asset("/assets/html/test.html", sa); + auto rteee = [&](const std::string& asset_path) -> std::string { + ret = samI.get_asset(asset_path, sa); een9_ASSERT_pl(ret == 0); return een9::form_http_server_response_200(sa.type, sa.content); + }; + if (req.uri_path == "/" || req.uri_path == "/list-rooms") { + return rteee("/assets/html/list-rooms.html"); } + if (req.uri_path == "/chat") { + return rteee("/assets/html/chat.html"); + } + if (req.uri_path == "/profile") { + return rteee("/assets/html/profile.html"); + } + if (req.uri_path == "/registration") { + return rteee("/assets/html/registration.html"); + } + /* Trying to interpret request as asset lookup */ ret = samI.get_asset(req.uri_path, sa); if (ret >= 0) { return een9::form_http_server_response_200(sa.type, sa.content);