|
NAMEkhttp_head —
emit one HTTP header for kcgi
LIBRARYlibrary “libkcgi”SYNOPSIS#include <sys/types.h>
#include <stdarg.h>
#include <stdint.h>
#include <kcgi.h>
enum kcgi_err
extern const char *const kresps[KRESP__MAX]; DESCRIPTIONThekhttp_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
See khttp_body(3) for a discussion on the “Content-Encoding” header: do not specify this header before doing so! RETURN VALUESThekhttp_head () function returns an
enum kcgi_err indicating the error state.
EXAMPLESTo 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 ALSOkcgi(3), khttp_body(3), khttp_parse(3)STANDARDSRFC 2616, section 14: “Header Field Definitions”.The example references RFC 6265, section 4.1: “Set-Cookie”. AUTHORSThekhttp_head () function was written by
Kristaps Dzonsons
<kristaps@bsd.lv>.
Visit the GSP FreeBSD Man Page Interface. |