NNG_HTTP_CONN_WRITE_RES(3http)

πŸ“¦ version 1.11, in alpine 3.24

πŸ’… NNG_HTTP_CONN_WRITE_RES(3http) β€” the nng_http_conn_write_res glow-up πŸ¦‹

okay bestie, so this one lives in the NNG Reference Manual and honestly? it's a handy little icon. sit down, hydrate, let's get into it πŸ’–


✨ NAME ✨

nng_http_conn_write_res β€” write HTTP response, periodt 🌸


πŸŽ€ SYNOPSIS πŸŽ€

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

void nng_http_conn_write_res(nng_http_conn *conn, nng_http_res *res,
    nng_aio *aio);

πŸ¦‹ DESCRIPTION πŸ¦‹

so nng_http_conn_write_res() kicks off an asynchronous write of the HTTP response res onto the connection conn. like, it starts the whole thing and then dips. the entire response goes out β€” headers and all β€” and if there's a response body present, that goes too, no crumbs left behind ✨ (you can set that body with nng_http_res_set_data() or nng_http_res_copy_data(), iykyk πŸ’…)

this function returns immediately, with no return value. none. zero. nada. it's giving "I'll text you later" energy 😭 the completion of the operation is signaled through the aio, and you grab the final result with nng_aio_result(). that result is either zero or an error code β€” that's it, that's the whole vibe check.

πŸ’œ Persistent Connections

by default, for HTTP/1.1 connections, the connection stays open and gets reused to receive new requests. iconic, efficient, environmentally friendly, we love a sustainable queen 🌈

BUT β€” if the res contains a header of Connection: with a value of Close (case-insensitive, so don't come at me with cLoSe), or the response corresponds to HTTP/1.0, then the connection is closed immediately after sending the response. boom, done, goodbye πŸ‘‹

🫢 note note note β€” lowkey consider using the nng_http_client_transact() or nng_http_conn_transact() functions instead? they give you a much simpler interface for performing a complete HTTP client transaction. main character energy fr fr, way less work on your end.

⭐ RETURN VALUES ⭐

None. nothing. it said what it said πŸ’€


πŸ”₯ ERRORS πŸ”₯

  • NNG_ECANCELED β€” the operation was canceled. rip, someone hit the brakes 😭
  • NNG_ECLOSED β€” the connection was closed. doors shut, no entry πŸšͺ
  • NNG_ECONNRESET β€” the peer closed the connection. not you getting ghosted by the other side πŸ’€
  • NNG_ENOMEM β€” insufficient free memory to perform the operation. your RAM said "bestie no" πŸ™ˆ
  • NNG_ENOTSUP β€” HTTP operations are not supported. wrong universe entirely, not our department 🧚
  • NNG_ETIMEDOUT β€” timeout waiting for data from the connection. it's been 84 years… ⏳

🌸 SEE ALSO 🌸

go read them, they're all slay, I promise πŸ‘‘


and that's the whole page, bestie!! πŸ’–βœ¨πŸŽ€ sourced from the NNG Reference Manual, dated 2026-01-13, filed under NNG_HTTP_..._WRITE_RES(3http) β€” mwah, go write some responses, you absolute legend πŸ«ΆπŸ¦‹β­

πŸ“¦ where this page comes from