FreeBSD Manual Pages
KHTTP_HEAD(3) BSD Library Functions Manual KHTTP_HEAD(3) NAME khttp_head -- emit one HTTP header for kcgi LIBRARY library "libkcgi" SYNOPSIS #include <sys/types.h> #include <stdarg.h> #include <stdint.h> #include <kcgi.h> enum kcgi_err khttp_head(struct kreq *req, const char *key, const char *fmt, ...); extern const char *const kresps[KRESP__MAX]; DESCRIPTION The khttp_head() function takes a kcgi(3) context req that was previously initialised by khttp_parse(3) and emits one HTTP header with the given HTTP response key. The fmt string and variable arguments, which follow printf(3) syntax, form the corresponding value in the HTTP response. This function may only be invoked prior to khttp_body(3); otherwise, its behaviour is undefined. The kresps global array, indexed with the KRESP_* symbolic constants de- fined in <kcgi.h>, provides standard HTTP key names. Use it for the key argument to avoid typos. See khttp_body(3) for a discussion on the "Content-Encoding" header: do not specify this header before doing so! RETURN VALUES The khttp_head() function returns an enum kcgi_err indicating the error state. KCGI_OK Success (not an error). KCGI_ENOMEM Internal memory allocation failure. KCGI_SYSTEM Internal system error writing to the output stream. KCGI_HUP The output connection has been terminated. For FastCGI connec- tions, the current connection should be released with khttp_free(3) and parse loop reentered. EXAMPLES To emit a session cookie (one-year expiration date) with key ckey and value cval for the global path, one may invoke the following. Assume that r is a pointer to a struct kreq successfully initialised by khttp_parse(3). const char *ckey = "foo", *cval = "bar"; char buf[64]; khttp_epoch2str(time(NULL) + 31536000, buf, 64); khttp_head(r, kresps[KRESP_SET_COOKIE], "%s=%s; path=/; expires=%s", ckey, cval, buf); SEE ALSO kcgi(3), khttp_body(3), khttp_parse(3) STANDARDS RFC 2616, section 14: "Header Field Definitions". The example references RFC 6265, section 4.1: "Set-Cookie". AUTHORS The khttp_head() function was written by Kristaps Dzonsons <kristaps@bsd.lv>. BSD July 11, 2020 BSD
NAME | LIBRARY | SYNOPSIS | DESCRIPTION | RETURN VALUES | EXAMPLES | SEE ALSO | STANDARDS | AUTHORS
Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=khttp_head&sektion=3&manpath=FreeBSD+13.0-RELEASE+and+Ports>