NNG_HTTP_RES_COPY_DATA(3http)

πŸ“¦ version 1.11, in alpine 3.24

πŸ’– NAME πŸ’–

nng_http_res_copy_data β€” copy HTTP response body. And yes bestie, we’re in the NNG Reference Manual for this one πŸ’…βœ¨


✨ SYNOPSIS ✨

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

int nng_http_res_copy_data(nng_http_res *res, const void *body, size_t size);

🌸 DESCRIPTION 🌸

Okay so nng_http_res_copy_data() makes a copy of body β€” and that body is of size size β€” then sets the HTTP body for the response res to that copy. The copy gets deallocated automatically when res is freed, so no manual cleanup drama πŸ’–

The copied body data will be automatically sent with the response when it’s sent using nng_http_conn_write_res(). Slay.

This also updates the relevant Content-Length header of res. Lowkey important, fr fr πŸ‘‘

🚨 Note: the current framework does not support sending data via chunked transfer-encoding.
🫢 Tip: to avoid copying data, the nng_http_res_set_data() may be used instead.
πŸŽ€ Tip: it is a good idea to also set the Content-Type header.

⭐ RETURN VALUES ⭐

This function returns 0 on success, and non-zero otherwise. That’s the whole vibe check 😌


πŸ’€ ERRORS πŸ’€

  • NNG_ENOMEM β€” insufficient memory to perform the operation.
  • NNG_ENOTSUP β€” no support for HTTP in the library.

πŸ¦‹ SEE ALSO πŸ¦‹


That’s the tea πŸ“ This page is signing off from 2026-01-13, under the iconic title NNG_HTTP_RES_COPY_DATA(3http) β€” periodt πŸ’…βœ¨

πŸ“¦ where this page comes from