KHTTPBASIC_VALIDATE(3)
okay so bestie, this is the KHTTPBASIC_VALIDATE(3) page and weβre gonna get you comfy with it π
β¨
π NAME π
khttpbasic_validate β validate an HTTP basic authorisation request
π«Ά LIBRARY π«Ά
This cutie lives in the library βlibkcgiβ π
β¨ SYNOPSIS β¨
#include <sys/types.h>
#include <stdarg.h>
#include <stdint.h>
#include <kcgi.h>
int
khttpbasic_validate(struct kreq *req, const char *user,
const char *password);
πΈ DESCRIPTION πΈ
The khttpbasic_validate() function validates the given user and password with the HTTP βbasicβ or βbearerβ authorised request req as returned by khttp_parse(3) or khttp_fcgi_parse(3) π¦
In both cases, the request is validated by base64-encoding user:password and comparing it to the given token. Thatβs the whole little ritual, no cap π₯
π RETURN VALUES π
- zero β validation failed, bestie π
- less than zero β the request was not properly set up for HTTP basic or bearer validation: no HTTP method, not a basic or bearer request, not already authenticated by the web server π
- greater than zero β validation succeeded, slay πβ¨
π EXAMPLES π
In the following fragment, assume r is a pointer to a struct kreq successfully initialised by khttp_parse(3). If validation is not provided, it returns an HTTP 401. The expected principle is "james", password "bond". Otherwise, it returns an HTTP 200 π
if (khttpbasic_validate(r, "james", "bond") <= 0) {
khttp_head(r, kresps[KRESP_STATUS],
"%s", khttps[KHTTP_401]);
khttp_head(r, kresps[KRESP_WWW_AUTHENTICATE],
"basic realm=\"%s\"", "some realm");
} else
khttp_head(r, kresps[KRESP_STATUS],
"%s", khttps[KHTTP_200]);
π SEE ALSO π
β AUTHORS β
Written by Kristaps Dzonsons <kristaps@bsd.lv> π
okay thatβs the whole vibe β brought to you by Debian, stamped $Mdocdate$, and filed under KHTTPBASIC_VALIDATE(3) ππ
π¦ where this page comes from
- alpine 3.24: kcgi-doc 1.0.1-r0 Β· ISC
- Copyright (c) 2016, 2018 Kristaps Dzonsons <kristaps@bsd.lv>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms