NNG_HTTP_RES_SET_HEADER(3http)
π nng_http_res_set_header
okay so bestie, this is a page straight out of the NNG Reference Manual β the 3http section, to be exact β and it's all about one very specific little glow-up move for your HTTP responses. slay. let's get into it π
β¨ NAME β¨
nng_http_res_set_header β set HTTP response header. that's it, that's the whole vibe. one job, done iconically π
π¦ SYNOPSIS π¦
#include <nng/nng.h>
#include <nng/supplemental/http/http.h>
int nng_http_res_set_header(nng_http_res *res, const char *key,
const char *val);
look at her. three arguments, returns an int, no drama πΈ
π DESCRIPTION π
so nng_http_res_set_header() sets the HTTP header for the response res, and it sets the key to the val. simple as that, no cap.
both key and val are copied β like, the function keeps its own little copy, so you don't have to stress about what happens to your strings afterwards. and here's the main character move: any previous header with the same key gets replaced. out with the old, in with the new π«Ά
π‘ Tip β if you don't want to replace, and you'd rather stack up extra headers with the same key, go see nng_http_res_add_header(). she's the "and also add this" girlie.
okay now the important detail nobody reads until it bites them π the value of key is case insensitive, and it should not include the final colon in an HTTP header. so for example, specifying Host or hOSt are equivalent β same thing, literally β whereas the value Host: is not a legal header key. that colon? leave it in the drafts bestie, don't invite it π
π₯ RETURN VALUES π₯
this function returns 0 on success, and non-zero otherwise. classic. iconic. predictable queen π
π ERRORS π
NNG_ENOMEMβ insufficient memory to perform the operation. the machine said "not today" π not enough memory for what you're trying to do.NNG_ENOTSUPβ no support for HTTP in the library. like, the HTTP machinery just isn't there in this build. can't do it π«
π SEE ALSO π
the whole friend group, go say hi:
nng_http_res_alloc(3http)nng_http_res_add_header(3http)nng_http_res_del_header(3http)nng_http_res_get_header(3http)nng(7)
<div>okay that's the whole page, mwah π this one's from the NNG reference manual, dated 2026-01-13, and the header bar up top spells her name roughly NNG_HTTP_...SET_HEADER(3http) β yes it's abbreviated, no we don't know why, we still love her. go set some headers, bestie, you're gonna ate it up βπ§ββοΈπ</div>
π¦ 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