KHTTP_BODY(3) Library Functions Manual KHTTP_BODY(3)


khttp_body, khttp_body_compressclose the HTTP header sequence for kcgi


library “libkcgi”


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


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:
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.
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.
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.


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.


kcgi(3), khttp_head(3), zlib(3)


The khttp_body function was written by Kristaps Dzonsons <>.
September 22, 2017 OpenBSD 5.8