From 6aac1c31c7d3084af047adb2ce8fdbe0ddd5c3fd Mon Sep 17 00:00:00 2001 From: VersusTuneZ Date: Mon, 14 Oct 2024 19:43:30 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20that=20request.Body=20cont?= =?UTF-8?q?ains=20not=20full=20http=20request=20after=20parsing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes possible to parse json or other stuff out of it instead of seeing the full message that is not needed anyway :) --- Includes/Server.h | 3 ++- Source/RequestHandler.cpp | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Includes/Server.h b/Includes/Server.h index 605dd19..0179a90 100644 --- a/Includes/Server.h +++ b/Includes/Server.h @@ -21,6 +21,7 @@ public: void Stop() { m_IsExit = true; } Ref &GetRouter() { return m_Router; } Ref &GetServerConfig() { return m_ServerConfig; } + Ref &GetRequestHandler() { return m_RequestHandler; } Ref &Middleware(); @@ -44,4 +45,4 @@ protected: protected: friend RequestHandler; }; -} \ No newline at end of file +} diff --git a/Source/RequestHandler.cpp b/Source/RequestHandler.cpp index 76c8560..d053e28 100644 --- a/Source/RequestHandler.cpp +++ b/Source/RequestHandler.cpp @@ -68,6 +68,8 @@ void ParseParameters(Request &request, RequestHandler &requestHandler) { request.URI = uri.substr(0, hasURLParameters); } + request.Body = GetPostBody(request.Body); + if (request.Method == HttpMethod::HEAD || request.Method == HttpMethod::GET || request.Method == HttpMethod::OPTIONS) return; @@ -78,11 +80,11 @@ void ParseParameters(Request &request, RequestHandler &requestHandler) { return; auto &key = contentType.GetFirst(); if (key == "application/x-www-form-urlencoded") { - ParseParameterString(request, GetPostBody(request.Body)); + ParseParameterString(request, request.Body); } else { if (requestHandler.HasBodyParser(key)) { auto &func = requestHandler.GetBodyParser(key); - func(request, GetPostBody(request.Body)); + func(request, request.Body); } } }