KCGIREGRESS(3)
okay bestie, this is kcgiregress(3) from the Library Functions Manual β the whole regression-framework-for-kcgi situation β and it's lowkey iconic. π¦
π NAME π
okay so kcgiregress, kcgi_regress_cgi, kcgi_regress_fcgi β regression framework for kcgi. periodt. π
πΈ LIBRARY πΈ
the library is literally βlibkcgiregressβ β yes bestie, that's the one. π«Ά
β¨ SYNOPSIS β¨
include this header, bestie:
#include <kcgiregress.h>
int
kcgi_regress_cgi(int (*client)(void *), void *clientData,
int (*server)(void *), void *serverData);
int
kcgi_regress_fcgi(int (*client)(void *), void *clientData,
int (*server)(void *), void *serverData);
π DESCRIPTION π
okay so this is the automated testing platform for kcgi(3) β it lets you have emulated CGI or FastCGI environments over a local network port. no cap. β¨
- the server callback β it gets invoked with argument
serverArgwithin a CGI or FastCGI environment as if it were spawned by a web server, upon which the usualkhttp_parse(3)orkhttp_fcgi_init(3)andkhttp_fcgi_parse(3)functions are usually used to test behaviour. π - the client callback β it communicates with the server over port
17123. usually this is orchestrated withlibcurl(3). π - the port number β it is fixed. not flexible, not vibes-based, fixed.
17123. π₯ - allowed methods β clients are restricted to the HTTP
GET,OPTIONS, andPOSTmethods. that's the list, bestie. π
both of these callbacks must return zero on failure, non-zero on success. yes, zero is the fail vibe, non-zero is the slay vibe. π«Ά
π¨ technical caveat, keep it clear: zero = failure, non-zero = success. do not flip it, i'm begging. π
to compile and link, use pkg-config(1) as follows:
% cc `pkg-config --cflags kcgi-regress` -c -o sample.o sample.c
% cc -o sample sample.o `pkg-config --libs kcgi-regress`
kcgi(3) components should use their respective pkg-config(1) identifiers, such as "kcgi-json" for kcgijson(3) output. applications using libcurl(3) should further use curl-config(1) as well, or on some systems, pkg-config(1) with "libcurl". iykyk. π
β RETURN VALUES β
these functions return zero on failure, non-zero on success. that's it, that's the contract, and it is giving very simple very iconic. π
π¦ EXAMPLES π¦
the following regression test simply checks that the server responds. its only check is for operation and HTTP status code (201). yes bestie, just vibes and a status code. π
#include <stdarg.h>
#include <stdint.h>
#include <stdlib.h>
#include <curl/curl.h>
#include <kcgi.h>
#include <kcgijson.h>
#include <kcgiregress.h>
static int
server(void *arg)
{
struct kreq r;
if (khttp_parse(&r, NULL, 0, NULL, 0, 0) != KCGI_OK)
return 0;
khttp_head(&r, kresps[KRESP_STATUS],
"%s", khttps[KHTTP_201]);
khttp_head(&r, kresps[KRESP_CONTENT_TYPE],
"%s", kmimetypes[KMIME_APP_JSON]);
khttp_body(&r);
khttp_free(&r);
return 1;
}
static int
client(void *arg)
{
CURL *curl;
long http;
if ((curl = curl_easy_init()) == NULL)
return 0;
curl_easy_setopt(curl, CURLOPT_URL,
"http://localhost:17123/index.json");
if (curl_easy_perform(curl) != CURLE_OK)
return 0;
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http);
curl_easy_cleanup(curl);
curl_global_cleanup();
return http == 201;
}
int
main(void)
{
return kcgi_regress_cgi
(client, NULL, server, NULL) ? 0 : 1;
}
to compile this simple regression test, the kcgi(3), kcgiregress(3), kcgijson(3), and libcurl(3) libraries and headers are needed, along with further dependencies. let the file be named sample.c. π
% export PKGS="kcgi-regress kcgi-json libcurl"
% cc `pkg-config --cflags $PKGS` -c sample.c
% cc -o sample sample.o `pkg-config --libs $PKGS`
this assumes that libcurl(3) has its configuration recognised by pkg-config(1), which isn't always the case: sometimes curl-config(1) is required. so if it acts up, that's the plot twist. π
π AUTHORS π
written by Kristaps Dzonsons <kristaps@bsd.lv>. iconic behavior, honestly. π
signed off from the Debian source/version, dated $Mdocdate$, for KCGIREGRESS(3) β mwah! π
π¦ where this page comes from
- alpine 3.24: kcgi-doc 1.0.1-r0 Β· ISC
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms