NNG_HTTP_RES_SET_DATA(3http)

πŸ“¦ version 1.11, in alpine 3.24

πŸ’… 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 with res that gets automatically deallocated when res is freed, go look at nng_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 πŸ¦‹


that's the whole page, bestie, no cap 🧚 go set some data and hydrate πŸ’§

sign-off: this was NNG Reference Manual, page dated 2026-01-13, section NNG_HTTP_RES_SET_DATA(3http). mwah πŸ’‹
πŸ“¦ where this page comes from