🐛 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; }
Ref<Router> &GetRouter() { return m_Router; }
Ref<ServerConfig> &GetServerConfig() { return m_ServerConfig; }
Ref<RequestHandler> &GetRequestHandler() { return m_RequestHandler; }
Ref<MiddleWareHandler> &Middleware();

View file

@ -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);
}
}
}