NNG_HTTP_REQ_SET_DATA(3http)
π nng_http_req_set_data(3http) π
okay bestie, so this one is from the NNG Reference Manual β it's nng_http_req_set_data(3http) and it's honestly such a vibe. Let's get into it π«Ά
β¨ NAME β¨
nng_http_req_set_data β set HTTP request body πΈ
π SYNOPSIS π
#include <nng/nng.h>
#include <nng/supplemental/http/http.h>
int nng_http_req_set_data(nng_http_req *req, const void *body, size_t size);
π DESCRIPTION π
so nng_http_req_set_data() literally sets the HTTP body that belongs to the request req to body, and the size of that body to size. like, no cap, that's the whole job π
and then β this is the slay part β that body data gets automatically sent with the request when it's sent using nng_http_conn_write_req(). iconic behaviour, honestly π
it ALSO updates the relevant Content-Length header of req. the way it just handles that for you?? main character energy fr β¨
β οΈ Note β heads up bestie: the current framework does not support sending data via chunked transfer-encoding. so like, don't come for it, it's just not that girl yet π
now, important thing, i need you to hear me on this one: the body is not copied π¨ so you (the caller) must ensure that it stays available until the req is deallocated. like keep it alive, bestie, don't let it ghost you π
π§ Tip β if you want a local copy allocated with req that gets automatically deallocated when req is freed, go look at nng_http_req_copy_data(). she does the copying for you π
π¦ Tip β it is a really good idea to also set the Content-Type header. like, strongly recommend. do it. periodt. π
β RETURN VALUES β
this function returns 0 on success, and non-zero otherwise. that's it, that's the contract π
π₯ ERRORS π₯
NNG_ENOMEMβ insufficient memory to perform the operation π (she ran out of room, it happens)NNG_ENOTSUPβ no support for HTTP in the library π (the library said "not today")
π SEE ALSO π
nng_http_conn_write_req(3http)nng_http_req_alloc(3http)nng_http_req_copy_data(3http)nng_http_req_set_header(3http)nng(7)
okay that's the whole page, you ate that π go set some request bodies and be the icon you are π
β with love, from the NNG Reference Manual, dated 2026-01-13, version of NNG_HTTP_REQ_SET_DATA(3http) β¨π
π«Ά
π¦ 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