nanomsg next generation NNG  
Home GitHub Documentation

This documentation is for version v1.2.2 of nng, but the latest released version is v1.8.0. see the documentation for v1.8.0 for the most up-to-date information.
nng_http_handler_collect_body(3http)

SYNOPSIS

#include <nng/nng.h>
#include <nng/supplemental/http/http.h>

int nng_http_handler_collect_body(nng_http_handler *handler, bool want, size_t maxsz);

DESCRIPTION

The nng_http_handler_collect_data() function causes the handler to collect any request body that was submitted with the request, and attach it to the nng_http_req before the handler is called.

Subsequently the data can be retrieved by the handler from the request with the nng_http_req_get_data() function.

The collection is enabled if want is true. Furthermore, the data that the client may sent is limited by the value of maxsz. If the client attempts to send more data than maxsz, then the request will be terminated with a 400 “Bad Request” status.

Limiting the size of incoming request data can provide protection against denial of service attacks, as a buffer of the client-supplied size must be allocated to receive the data.

In order to provide an unlimited size, use (size_t)-1 for maxsz. The value 0 for maxsz can be used to prevent any data from being passed by the client.

The built-in handlers for files, directories, and static data limit the maxsz to zero by default. Otherwise the default setting is to enable this capability with a default value of maxsz of 1 megabyte.

The handler looks for data indicated by the Content-Length: HTTP header. If this header is absent, the request is assumed not to contain any data.
This specifically does not support the Chunked transfer-encoding. This is considered a bug, and is a deficiency for full HTTP/1.1 compliance. However, few clients send data in this format, so in practice this should create few limitations.

RETURN VALUES

This function returns 0 on success, and non-zero otherwise.

ERRORS

NNG_ENOTSUP

No support for HTTP in the library.

NNG Reference Manual vv1.2.2 © 2019 Staysail Systems, Inc, © 2018 Capitar IT Group BV
This document is supplied under the MIT License.
nanomsg™ and nng™ are trademarks of Garrett D'Amore.