NNG_HTTP_HANDLER_SET_HOST(3http)

πŸ“¦ version 1.11, in alpine 3.24

✨ NNG_HTTP_HANDLER_SET_HOST ✨

okay bestie, welcome to the nng_http_handler_set_host page πŸ’… this one lives in the NNG Reference Manual and it's honestly such a little icon β€” short, sweet, and it does exactly one thing. let's get into it πŸŽ€


🌸 NAME 🌸

nng_http_handler_set_host β€” set the host for an HTTP handler 🫢


✨ SYNOPSIS ✨

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

int nng_http_handler_set_host(nng_http_handler *handler, const char *host);

πŸ’– DESCRIPTION πŸ’–

so the way that nng_http_handler_set_host() works is: it limits the scope of the handler πŸ‘‘ like, instead of the handler being out here matching everything, it only gets called when the specified host matches the value of the Host: HTTP header. no cap. that's the whole vibe check πŸ”₯

🧚 Tip: this is literally how you build servers with multiple handlers for virtual hosting. main character energy fr fr.

the value of the host can include a colon and a port, and it should match exactly the value of the Host header that the client sent πŸ’… (canonicalization of the host name is performed though, so don't stress about that part 🩷)

🌈 Tip: since the server framework does not support listening on multiple ports, the port number can be elided. the matching test only considers the hostname or IP address, and ignores any trailing port number ⭐

πŸ¦‹ RETURN VALUES πŸ¦‹

this function returns 0 on success, and non-zero otherwise 😭 (yes that's the whole thing, she's simple and we love her)


πŸ’€ ERRORS πŸ’€

  • NNG_ENOMEM β€” not enough free memory to do the thing 🫠 like there's just insufficient free memory to perform the operation.
  • NNG_ENOTSUP β€” no support for HTTP in the library πŸ™ˆ as in, this build of the library doesn't do HTTP at all.

πŸ”₯ SEE ALSO πŸ”₯


that's the whole page bestie, go forth and host virtually πŸ‘‘πŸ’œ

mwah πŸ’‹ β€” this has been the NNG Reference Manual, NNG_HTTP_...R_SET_HOST(3http), dated 2026-01-13. see u in the next manpage 🌸

πŸ“¦ where this page comes from