From 3e4c7c993bbbe2bdeb563fa888b900d01c4be4a1 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Mon, 6 Oct 2025 01:23:20 +0200 Subject: Fix design issues with async responses, add async example struct http_response did not provide users any void * that could be used to maintain a state between calls to an asynchronous HTTP response. On the other hand, the user pointer could not be used for this purpose, since it is shared among all HTTP clients for a given struct handler instance. Moreover, the length callback was still not supporting this feature, which in fact might be required by some users. Implementing this was particularly challenging, as this broke the current assumption that all bytes on a call to http_read were being processed. Now, since a client request can only be partially processed because of the length callback, http_read must take this into account so that the remaining bytes are still available for future calls, before reading again from the file descriptor. --- include/libweb/http.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/libweb/http.h b/include/libweb/http.h index f18b5c4..87edf8a 100644 --- a/include/libweb/http.h +++ b/include/libweb/http.h @@ -109,7 +109,15 @@ struct http_response unsigned long long n; size_t n_headers; void (*free)(void *); - int (*step)(const struct http_payload *, struct http_response *, void *); + void *step_args; + + union http_step + { + int (*length)(unsigned long long len, const struct http_cookie *c, + struct http_response *r, void *user, void *step_args); + int (*payload)(const struct http_payload *p, struct http_response *r, + void *user, void *step_args); + } step; }; struct http_cfg -- cgit v1.2.3