NNG_HTTP_HIJACK(3http)

πŸ“¦ version 1.11, in alpine 3.24

✨ NNG_HTTP_HIJACK ✨

ok so this is the nng_http_hijack page from the NNG Reference Manual (yes, 3http section, we're fancy) β€” and bestie, it's literally about stealing a connection. let me explain πŸ’…


🌸 SYNOPSIS 🌸

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

void nng_http_hijack(nng_http_conn *conn);

like, that's the whole vibe. one function, one argument, zero return value. iconic honestly πŸŽ€


πŸ¦‹ DESCRIPTION πŸ¦‹

okay so nng_http_hijack() hijacks the connection conn, which causes it to be disassociated from the HTTP server where it was created. like, the connection just ✨leaves✨. it's not the server's problem anymore. main character energy fr fr.

the purpose of this whole thing is to build HTTP upgraders (think WebSocket πŸ‘‘), where the underlying HTTP connection gets taken over for some other purpose β€” and should not be used any further by the server. the server is done with it. it's moved on. it's not texting back. πŸ’€

this function is most useful when called from a handler function. (see nng_http_handler_alloc() β€” go look it up, iykyk 🌈)

Note 🫢 β€” it is the responsibility of the caller to dispose of the underlying connection when it is no longer needed. yes, you. not the server. you. 😭 furthermore, the HTTP server will no longer send any responses to the hijacked connection, so the caller should do that as well if appropriate. (see nng_http_conn_write_res() β€” that's your girl for writing responses ✨)
Tip 🧚 β€” this function is intended to facilitate use cases that involve changing the protocol from HTTP, such as WebSocket. most applications will never need to use this function. so if you're here and you're like "do i need this?" the answer is probably no πŸ“

⭐ RETURN VALUES ⭐

None. literally nothing. it's void. it gives you nothing back and honestly? respect πŸ’…


πŸ’œ ERRORS πŸ’œ

so the return value is None, but there's still an error list, which is a choice, and we support it πŸŽ€

  • NNG_ECLOSED β€” the connection was closed. πŸ’€
  • NNG_ENOMEM β€” insufficient free memory exists. 😭
  • NNG_ENOTSUP β€” HTTP not supported. πŸ™ˆ

🌟 SEE ALSO 🌟


and that's the whole page bestie!! βœ¨πŸ’– go hijack responsibly 🫢

source/version: NNG Reference Manual, section 3http Β· dated 2026-01-13 β€” mwah πŸ’‹

πŸ“¦ where this page comes from