From 5a6f30440b66fe6713acb9d979dc3e6624e4c36a Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Tue, 23 Sep 2025 22:03:57 +0200 Subject: Implement async HTTP responses Sometimes, library users cannot return a HTTP response as soon as the request is received, or the operations that are required to generate it can take a long time. In order to solve this, libweb adds a new member to struct http_response, namely step, which must be assigned to a function whenever a HTTP response should be generated in a non-blocking manner. Leaving the function pointer as null will fall back to the default behaviour. --- doc/man7/libweb_http.7 | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'doc') diff --git a/doc/man7/libweb_http.7 b/doc/man7/libweb_http.7 index f11c1ef..c3bec8b 100644 --- a/doc/man7/libweb_http.7 +++ b/doc/man7/libweb_http.7 @@ -562,6 +562,7 @@ struct http_response unsigned long long \fIn\fP; size_t \fIn_headers\fP; void (*\fIfree\fP)(void *); + int (*\fIstep\fP)(const struct http_payload *, struct http_response *, void *); }; .EE .in @@ -669,6 +670,24 @@ is a valid pointer. Otherwise, .I free must be a null pointer. +.I step +allows implementations to generate a response in a non-blocking manner. +When a response is not immediately available when a payload is received, +.I step +must be assigned to a function that can generate it later. +.I libweb +shall then call this function immediately later, +without blocking other clients. +Assigning +.I step +to a null pointer falls back to the default behaviour +i.e., a response is returned immediately. +Note that a non-null +.I step +shall always take priority, thus ignoring any other information inside the +.I "struct http_response" +instance. + .SS Transport Layer Security (TLS) By design, .I libweb -- cgit v1.2.3