NEWS: Welcome to my new homepage! <3

feat: Added ext data to http_request_t & removed logging - libhttp - A basic HTTP Framework

libhttp

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

commit 5696a76b5f636da3b52bafbb027454a99bef5041
parent cf861bd198b2164266912b600ef16d0eae788020
Author: typable <contact@typable.dev>
Date:   Sat, 24 Aug 2024 12:04:45 +0200

feat: Added ext data to http_request_t & removed logging

Diffstat:
Mlibhttp.c | 35++++++++++++++++++++++++-----------
Mlibhttp.h | 1+
2 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/libhttp.c b/libhttp.c @@ -273,6 +273,9 @@ void http_request_free(http_request_t *request) { if (request->body != NULL) { free(request->body); } + if (request->ext_data != NULL) { + free(request->ext_data); + } } void http_response_free(http_response_t *response) { @@ -300,7 +303,17 @@ http_request_t http_read_request(conn_t *conn) { int ln = 0; int start = 0; char buffer[MAX_REQUEST_HEAD_SIZE]; - http_request_t request = { conn, NULL, NULL, NULL, NULL, 0, NULL, 0 }; + http_request_t request = { + .conn = conn, + .method = NULL, + .url = NULL, + .version = NULL, + .headers = NULL, + .headers_len = 0, + .body = NULL, + .body_len = 0, + .ext_data = NULL, + }; while (true) { char c; int read = http_read(conn, &c, 1); @@ -440,16 +453,16 @@ void *http_handle_client(void *ptr) { } http_request_t request = http_read_request(conn); if (request.method != NULL && request.url != NULL) { - long addr = ((struct sockaddr_in *) &request.conn->addr)->sin_addr.s_addr; - printf( - "%ld.%ld.%ld.%ld -> %s %s\n", - (addr ) & 0xff, - (addr >> 8) & 0xff, - (addr >> 16) & 0xff, - (addr >> 24) & 0xff, - request.method, - request.url - ); + // long addr = ((struct sockaddr_in *) &request.conn->addr)->sin_addr.s_addr; + // printf( + // "%ld.%ld.%ld.%ld -> %s %s\n", + // (addr ) & 0xff, + // (addr >> 8) & 0xff, + // (addr >> 16) & 0xff, + // (addr >> 24) & 0xff, + // request.method, + // request.url + // ); if (on_request_fn != NULL) { http_response_t response = on_request_fn(&request); http_write_response(conn, response); diff --git a/libhttp.h b/libhttp.h @@ -99,6 +99,7 @@ typedef struct { int headers_len; char *body; long body_len; + void *ext_data; } http_request_t; typedef struct {