NNG_HTTP_RES_SET_DATA(3http)
π NNG_HTTP_RES_SET_DATA(3http) β like, the whole vibe
okay so bestie, welcome to the nng_http_res_set_data page from the NNG Reference Manual (section 3http, iykyk). this one's short and sweet and honestly kinda iconic for how much it does in one line. let's get into it β¨
πΈ SYNOPSIS πΈ
#include <nng/nng.h>
#include <nng/supplemental/http/http.h>
int nng_http_res_set_data(nng_http_res *res, const void *body, size_t size);
π DESCRIPTION π
so nng_http_res_set_data() sets the HTTP body that's chillin' on the response res to body, and it sets the size of that body to size. that's it, that's the function π«Ά
and like, the glow-up? that body data gets automatically sent with the response when it's sent using nng_http_conn_write_res(). no extra steps, no manual labor, she just goes π
oh and she also updates the relevant Content-Length header of res for you. queen behavior, honestly π
β note: the current framework does not support sending data via chunked transfer-encoding. so likeβ¦ don't try it, bestie π
also super important: the body is not copied. the caller has to make sure it stays available until res is deallocated. so if you free that buffer early, that's on you and it will not be cute π
π tip: if you'd rather have a local copy allocated withresthat gets automatically deallocated whenresis freed, go look atnng_http_res_copy_data(). she's the low-effort option and honestly? slay.
π tip: it's a really good idea to also set the Content-Type header. like, please. for me. π
β¨ RETURN VALUES β¨
this function returns 0 on success, and non-zero otherwise. simple. clean. we love a straightforward return π
π ERRORS π
NNG_ENOMEMβ insufficient memory to perform the operation. your RAM said "no <3" πNNG_ENOTSUPβ no support for HTTP in the library. like, the library simply doesn't do HTTP, bestie. not applicable. π«
π¦ SEE ALSO π¦
nng_http_conn_write_res(3http)nng_http_res_alloc(3http)nng_http_res_copy_data(3http)nng_http_res_set_header(3http)nng(7)
that's the whole page, bestie, no cap π§ go set some data and hydrate π§
sign-off: this wasNNG Reference Manual, page dated2026-01-13, sectionNNG_HTTP_RES_SET_DATA(3http). mwah π
π¦ where this page comes from
- alpine 3.24: nng-doc 1.11-r0 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms