NE_SESSION_CREATE(3)
π¦ NE_SESSION_CREATE(3) π¦
okay bestie, welcome to the neon API reference β this is the neon manual, third section, and today's main character is NE_SESSION_CREATE. she sets things up. she's the beginning of the story. let's go π
β¨ NAME β¨
ne_session_create, ne_close_connection, ne_session_destroy β the trio that sets up HTTP sessions for you, closes the connection when you're done, and then cleans up the whole thing. three besties, one job π«Ά
πΈ SYNOPSIS πΈ
#include <ne_session.h>
ne_session *ne_session_create(const char *scheme, const char *host,
unsigned int port);
void ne_close_connection(ne_session *session);
void ne_session_destroy(ne_session *session);
okay so like, look at those signatures. gorgeous. <ne_session.h> is the header you need, and yeah, that's literally it π
π DESCRIPTION π
An ne_session object represents an HTTP session β think of it as a logical grouping of a whole sequence of HTTP requests you're making to a certain server. the way that everything in one session can share stuff? obsessed. any requests made using the session can use a persistent connection, share cached authentication credentials, and share any other common attributes. it's giving shared group chat energy π
A new HTTP session gets created with the ne_session_create function. the host and port parameters specify the origin server you're talking to, along with the scheme (usually "http"). and listen β before the first use of ne_session_create in a process, ne_sock_init(3) must have been called, so any global initialization needed by any libraries used by neon actually happens. do not skip this, i'm serious π
Wanna enable SSL/TLS for the session? pass the string "https" as the scheme, and then either register a certificate verification function (see ne_ssl_set_verify(3)) or trust the appropriate certificate (see ne_ssl_trust_cert(3), ne_ssl_trust_default_ca(3)). pick one, babes, but pick one β¨
The host parameter must follow the "host" grammar in Section 3.2.2 of RFC 3986[1] β which can be an IP-literal or a registered (DNS) hostname. valid examples of each, since i know you're gonna ask:
"198.51.100.42"β an IPv4 literal address"[2001:db8::42]"β an IPv6 literal, which MUST be enclosed in square brackets (yes literally must, all caps, no cap)"www.example.com"β a DNS hostname
The RFC 6874[2] syntax for scoped IPv6 link-local literal addresses is also permitted β for example "[fe80::1%25eth0]". fancy π
The scheme parameter is used to determine the URI for resources identified during request handling. other than the special handling of the string "https", no other interpretation or checking of the scheme is performed. like, none. zero vibe check. for example, if an HTTP-to-FTP proxy is configured, a scheme of "ftp" could be used to access resources. slay π¦
Wanna use a proxy server for the session? it must be configured (see ne_session_proxy(3)) before any requests are created from the session object. before, bestie. the order matters π
Further per-session options can be changed using the ne_set_session_flag(3) interface β go off π
If you know the session won't be used for a significant period of time, ne_close_connection can be called to close the connection, if one remains open. use of this function is entirely optional β no pressure β but it must not be called if there's a request active using the session. like, hard no π₯
Once a session has been completed, ne_session_destroy must be called to destroy the resources associated with the session. any subsequent use of the session pointer produces undefined behaviour (π not the undefined behaviour). and the session object must not be destroyed until after all associated request objects have been destroyed. last one out turns off the lights, periodt.
π§ NOTES π§
If a hostname is passed to ne_session_create, it will be resolved when the first request using the session is dispatched β so a DNS resolution failure can only be detected at that time (using the NE_LOOKUP error code). see ne_request_dispatch(3) for details, iykyk π
β RETURN VALUES β
ne_session_create will return a pointer to a new session object β and it never returns NULL. iconic behaviour honestly, no NULL checks needed, we love a reliable king π
π EXAMPLES π
Create and destroy a session:
ne_session *sess;
sess = ne_session_create("http", "host.example.com", 80);
/* ... use sess ... */
ne_session_destroy(sess);
look at her. create, use, destroy. the full lifecycle, the main character arc π
πΈ HISTORY πΈ
The scheme passed to ne_session_create is lower-cased internally from neon 0.37.0 onward β so passing "HtTpS" and "https" are equivalent. glow-up fr fr β¨ in earlier releases, the scheme is case-sensitive. so like, mind your version π
π SEE ALSO π
ne_ssl_set_verify(3)ne_ssl_trust_cert(3)ne_sock_init(3)ne_set_session_flag(3)ne_session_proxy(3)
go read them, they're all linked in the group chat π«Ά
π COPYRIGHT π
Copyright Β© 2001-2026 Joe Orton
π REFERENCES π
- Section 3.2.2 of RFC 3986 β https://www.rfc-editor.org/rfc/rfc3986#section-3.2.2
- RFC 6874 β https://www.rfc-editor.org/rfc/rfc6874
and that's the whole page bestie!! brought to you by neon, dated 03/20/2026, filed under NE_SESSION_CREATE(3) πβ¨ now go call ne_sock_init(3) first, i'm watching you πΈ
π¦ where this page comes from
- arch rolling: neon 0.37.1-1 Β· LGPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms