|KHTTP_HEAD(3)||Library Functions Manual||KHTTP_HEAD(3)|
khttp_head — emit
one HTTP header for kcgi
khttp_head(struct kreq *req,
const char *key, const char
extern const char *const kresps[KRESP__MAX];
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
The kresps global array, indexed with the
KRESP_* symbolic constants defined in
<kcgi.h>, provides standard
HTTP key names. Use it for the key argument to avoid
See khttp_body(3) for a discussion on the "Content-Encoding" header: do not specify this header before doing so!
khttp_head() function returns an
enum kcgi_err indicating the error state.
- Success (not an error).
- Internal memory allocation failure.
- Internal system error writing to the output stream.
- The output connection has been terminated. For FastCGI connections, the current connection should be released with khttp_free(3) and parse loop reentered.
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; khttp_epoch2str(time(NULL) + 31536000, buf, 64); khttp_head(r, kresps[KRESP_SET_COOKIE], "%s=%s; path=/; expires=%s", ckey, cval, buf);
RFC 2616, section 14: “Header Field Definitions”.
The example references RFC 6265, section 4.1: “Set-Cookie”.
khttp_head() function was written by
|September 23, 2021||OpenBSD 6.7|