🐛 fix that request.Body contains not full http request after parsing

This makes possible to parse json or other stuff out of it instead of
seeing the full message that is not needed anyway :)
This commit is contained in:
Maurice Grönwoldt 2024-10-14 19:43:30 +02:00
parent f001b24749
commit 6aac1c31c7
Signed by: versustunez
GPG key ID: 3DBA8C59A63DEE3A
2 changed files with 6 additions and 3 deletions

View file

@ -21,6 +21,7 @@ public:
void Stop() { m_IsExit = true; } void Stop() { m_IsExit = true; }
Ref<Router> &GetRouter() { return m_Router; } Ref<Router> &GetRouter() { return m_Router; }
Ref<ServerConfig> &GetServerConfig() { return m_ServerConfig; } Ref<ServerConfig> &GetServerConfig() { return m_ServerConfig; }
Ref<RequestHandler> &GetRequestHandler() { return m_RequestHandler; }
Ref<MiddleWareHandler> &Middleware(); Ref<MiddleWareHandler> &Middleware();
@ -44,4 +45,4 @@ protected:
protected: protected:
friend RequestHandler; friend RequestHandler;
}; };
} }

View file

@ -68,6 +68,8 @@ void ParseParameters(Request &request, RequestHandler &requestHandler) {
request.URI = uri.substr(0, hasURLParameters); request.URI = uri.substr(0, hasURLParameters);
} }
request.Body = GetPostBody(request.Body);
if (request.Method == HttpMethod::HEAD || request.Method == HttpMethod::GET || if (request.Method == HttpMethod::HEAD || request.Method == HttpMethod::GET ||
request.Method == HttpMethod::OPTIONS) request.Method == HttpMethod::OPTIONS)
return; return;
@ -78,11 +80,11 @@ void ParseParameters(Request &request, RequestHandler &requestHandler) {
return; return;
auto &key = contentType.GetFirst(); auto &key = contentType.GetFirst();
if (key == "application/x-www-form-urlencoded") { if (key == "application/x-www-form-urlencoded") {
ParseParameterString(request, GetPostBody(request.Body)); ParseParameterString(request, request.Body);
} else { } else {
if (requestHandler.HasBodyParser(key)) { if (requestHandler.HasBodyParser(key)) {
auto &func = requestHandler.GetBodyParser(key); auto &func = requestHandler.GetBodyParser(key);
func(request, GetPostBody(request.Body)); func(request, request.Body);
} }
} }
} }