GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
KHTTP_HEAD(3) FreeBSD Library Functions Manual KHTTP_HEAD(3)

khttp_head
emit one HTTP header for kcgi

library “libkcgi”

#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];

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 defined 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!

The 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[64];

khttp_epoch2str(time(NULL) + 31536000, buf, 64);

khttp_head(r, kresps[KRESP_SET_COOKIE],
  "%s=%s; path=/; expires=%s", ckey, cval, buf);

kcgi(3), khttp_body(3), khttp_parse(3)

RFC 2616, section 14: “Header Field Definitions”.

The example references RFC 6265, section 4.1: “Set-Cookie”.

The khttp_head() function was written by Kristaps Dzonsons <kristaps@bsd.lv>.
June 12, 2022 FreeBSD 13.1-RELEASE

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.