From 16cedec609c789fcfb0c6a219c608dd60766010d Mon Sep 17 00:00:00 2001 From: Samuel Vishesh Paul Date: Mon, 28 Oct 2024 22:09:45 +0530 Subject: [PATCH] Handle HTTP body extraction in request parsing This update ensures the HTTP body is correctly extracted and stored when parsing requests. It adds a check to determine the length of the body and allocates memory accordingly, improving the server's ability to handle incoming HTTP packets. Took 8 minutes --- src/tiny_http/tiny_http_server_lib.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/tiny_http/tiny_http_server_lib.c b/src/tiny_http/tiny_http_server_lib.c index ce2781f..ddf69ff 100644 --- a/src/tiny_http/tiny_http_server_lib.c +++ b/src/tiny_http/tiny_http_server_lib.c @@ -121,5 +121,11 @@ http_request *parse_http_request(const uint8_t *const http_packet, const size_t ptr += 2; } + ptr += 2; + if (ptr < http_packet_len) { + request->body_len = http_packet_len - ptr; + request->body = (uint8_t*) strndup((char *) http_packet + ptr, request->body_len); + } + return request; }