KHTTP_BODY(3)

NAME
khttp_body, khttp_body_compress - close the HTTP header sequence for kcgi

LIBRARY
libkcgi

SYNOPSIS
#include <sys/types.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <kcgi.h>
int
khttp_body(struct kreq *req);
int
khttp_body_compress(struct kreq *req, int compress);

DESCRIPTION
The khttp_body and khttp_body_compress functions terminate the zero or more khttp_head(3) calls for a kcgi(3) context. After these functions, invoking khttp_head(3) will result in undefined behaviour.

khttp_body_compress takes an additional argument, compress, that dictates whether compression should be enabled. If khttp_body is used, this argument is set as 1. The values for compress are as follows:

>0  Check whether the “Accept-Encoding” request header specified “gzip” with a non-zero or empty q-value. If so, emit the appropriate “Content-Encoding” header and try to enable write compression. This auto-compression setting is the default behaviour of khttp_body.

0   Do not check for the request header and do not emit “Content-Encoding”, but try to enable write compression anyway. This is useful for applications overriding the “Content-Encoding” header themselves and want to explicitly stipulate output compression.

<0  Simply open the document body: do not fiddle with compression at all. This is useful if the application will have complete control over the output stream. Calls to khttp_write(3) will be uncompressed.

If kcgi(3) is not built with zlib(3) support, compression is never enabled regardless the argument to khttp_body_compress(). If zlib(3) fails when enabling compression, the error is reported and compression is disabled.

RETURN VALUES
Both functions will return zero if compression was not enabled and non-zero if it was. Enabling means only that subsequent calls to khttp_write(3) and family will be compressed, not whether the compression “Content-Encoding” header was emitted.

SEE ALSO
kcgi(3), khttp_head(3), zlib(3)

AUTHORS
The khttp_body function was written by Kristaps Dzonsons <kristaps@bsd.lv>.