NEWS: Welcome to my new homepage! <3

fix: Fixed POST request read body bug - libhttp - A basic HTTP Framework

libhttp

A basic HTTP Framework
git clone git://192.168.2.2/libhttp
Log | Files | Refs | README

commit 4f5681279a82ad33373e70bf3de55e12e08a4c81
parent ab7b16f87f6a682c367aaf377aa4265bf7434145
Author: typable <contact@typable.dev>
Date:   Fri, 20 Sep 2024 13:19:52 +0200

fix: Fixed POST request read body bug

Diffstat:
Mlibhttp.c | 8+++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/libhttp.c b/libhttp.c @@ -403,9 +403,11 @@ http_request_t http_read_request(http_conn_t *conn) { char *content_length = http_header_get(&request, "Content-Length"); if (content_length != NULL) { request.body_len = strtol(content_length, NULL, 10); - request.body = malloc(sizeof(char) * (request.body_len + 1)); - http_read(conn, request.body, request.body_len); - request.body[request.body_len] = '\0'; + if (request.body_len > 0) { + request.body = malloc(sizeof(char) * (request.body_len + 1)); + http_read(conn, request.body, request.body_len); + request.body[request.body_len] = '\0'; + } } break; }